Огонь HTML Radio Button Event из моей формы Windows, но Jquery не может загрузить Dom
Имея 2 RadioButtons и 2 TextBox на моей форме окна, такие как rdbMale и rdbFemale, txtMale, txtFemale sililar, точно так же Radio Button и TextBox на моей HTML-странице. На странице Html я использую некоторые Jquery при первой загрузке dom. Я скрываю оба текстовых поля (txtMale, txtFemale), когда нажимаю кнопку-переключатель Male rdbMale, затем textbox txtMale - show и txtFemale - hide, аналогично, когда я нажимаю rdbFemale, затем Textbox txtMale это скрыть, а txtFemale это показать.
Я хочу выбрать эту операцию выбора радиокнопки в моей форме окна. когда я нажимаю переключатель, например кнопку rdbMale или rdbFemale(также в winform с 1 кнопкой SendToHtml), когда я нажимаю этот SendToHtml, соответствующее значение переключателя передается на страницу HTML (без муравьиной строки запроса и т. д.), и мое событие Jquery будет обрабатывать, но в моем случае значение проверки переключателем значения переключается на страницу HTML, но Jquery не будет работать для отображения и скрытия txtMale и txtFemale.
HTML-код
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Application</title>
<script type="text/javascript" language="javascript">
window.onload = body_Onload;
function body_Onload() {
document.getElementById("txtFirstName").focus();
}
</script>
<script type="text/javascript" src="../App_Script/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#txtMale,#txtFemale").hide();
$("input[name=Sex]").click(function () {
if ($("#radMale").attr('checked')) {
$("#txtMale").show();
$("#txtFemale").hide();
}
else {
$("#txtMale").hide();
$("#txtFemale").show();
}
});
});
</script>
</head>
<body>
<input id="radMale" type="radio" name="Sex" value="radMale" />
<label for="lblMale">
Male</label>
<input id="radFeMale" type="radio" name="Sex" value="radFeMale" />
<label id="lblFeMale">
Female</label><br />
<input type="text" id="txtMale" /><br />
<input type="text" id="txtFemale" /><br />
</body>
</html>
Класс C#
private SHDocVw.InternetExplorer TargetIE = null;
string url;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
txtMale.Visible = false;
txtFemale.Visible = false;
}
private void SendToHtml_Click(object sender, EventArgs e)
{
GetTheIEObjectFromSystem("Q_26773800");
SendTextToActiveElementWithSubmitOptionSet(false);
}
private void GetTheIEObjectFromSystem(string inurl = ".")
{
SHDocVw.ShellWindows SWs = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer internetExplorer in SWs)
{
if (internetExplorer.Document is mshtml.HTMLDocument)
{
url = internetExplorer.LocationURL;
TargetIE = internetExplorer;
return;
}
}
}
private void SendTextToActiveElementWithSubmitOptionSet(bool btnSubmit)
{
mshtml.IHTMLDocument2 document = null;
if (TargetIE != null)
{
document = TargetIE.Document as mshtml.IHTMLDocument2;
if (!document.activeElement.isTextEdit)
{
MessageBox.Show("Active element is not a text-input system");
}
else
{
HTMLInputElement HTMLI;
HTMLI = document.activeElement as HTMLInputElement;
var tag = HTMLI.document as mshtml.HTMLDocumentClass;
mshtml.IHTMLElementCollection hTMLElementCollection = tag.getElementsByTagName("input");
foreach (mshtml.HTMLInputElement el in hTMLElementCollection)
{
switch (el.id)
{
case "radMale":
if (radioButton1.Checked == true)
el.setAttribute("checked", "checked");
else
el.removeAttribute("checked");
break;
case "radFeMale":
if (radioButton2.Checked == true)
el.setAttribute("checked", "checked");
else
el.removeAttribute("checked");
break;
}
}
}
}
else
{
MessageBox.Show("open internet explorer.");
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
txtMale.Visible = true;
txtFemale.Visible = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
txtFemale.Visible = true;
txtMale.Visible = false;
}
Что мне нужно сделать, пока радио-кнопка выбрана из winform на HTML-страницу и запускает событие Jquery также из winform
1 ответ
Я решаю свою проблему, я просто вставляю код, который решает мою проблему, а не весь код
case "radMale":
if (radioButton1.Checked == true)
{
el.setAttribute("checked", "checked");
el.click();
}
else
el.removeAttribute("checked");
break;
case "radFeMale":
if (radioButton2.Checked == true)
{
el.setAttribute("checked", "checked");
el.click();
}
else
el.removeAttribute("checked");
break;
ИЛИ Так
case "radFeMale":
if (radioButton2.Checked == true)
{
elInput.setAttribute("checked", true);
elInput.click();
}
else
elInput.setAttribute("checked", false);
break;
case "txtMale":
elInput.value = textBox5.Text;
break;
case "txtFemale":
elInput.value = textBox6.Text;
break;