我有一個JavaScript函數。顯示/隱藏在onChange中。我想轉換它在jQuery中,如何做到這一點。如何將javascript函數轉換爲jquery
Javacript功能
function assocWindowOnLoad()
{
var option=document.getElementsByName("select_id");
document.getElementById('conent1').style.display='none';
document.getElementById('conent2').style.display='none';
}
function assocWindowOnChange(val)
{
//if user select option Select from drop down
if(val=='')
{
//alert("Please Select option from the dropdown");
assocWindowOnLoad();
}
else
{
//Show or hide piece of code depending on user input
document.getElementById('conent1').style.display=(val=='no')?'none':'block';
document.getElementById('conent2').style.display=(val=='no')?'block':'none';
}
}
HTML代碼
<body onLoad="assocWindowOnLoad();">
<select name="select_id" id="select_id" onChange="assocWindowOnChange(this.value);" >
<option value='' selected="selected">Select</option>
<option value='no'>1st Option</option>
<option value='yes'>Second Option</option>
</select>
<div id="conent1" class="hide">
<p>some content</p>
</div>
<div id="conent1" class="hide">
<p>some content</p>
</div>
<div id="conent2" class="hide">
<p>some content</p>
</div>
</body>
yeah ............. :) – Vivek