[英]how to assign the html value to the php variable without post or get method
in my program i had a php value $test = 2 using this value i done some operation for example: in my page i had a 2 block A and B and one select box. 在我的程序中,我有一个php值$ test = 2,使用该值我做了一些操作,例如:在我的页面中,我有2个块A和B和一个选择框。 If the test value is A it enable the div A, if the value is B it hide div A and also i am able to show and hide the div using the select box onchange event.
如果测试值为A,则启用div A;如果测试值为B,则隐藏div A,并且我能够使用选择框onchange事件显示和隐藏div。 please check my sample code given below
请检查下面给出的我的示例代码
$test = $_GET["id"];
<select name="hideme" id="hideme" onchange="enableme();">
<option value="A">Show</option>
<option value="B">Hide</option>
</select>
if($test == 'A') {
<div id="div1" name="div1">
xxxxxxxxxxxxx
</div>
}
Js Function : Js功能:
function enableme() {
if(document.getElementByID('hideme').value == "A") {
document.getElementById.style.display ="block";
} else {
document.getElementById.style.display ="none";
}
}
my issue is at fist time using the $test($_get) value it show the correct div but the on change event is not working because of , if condition. 我的问题是在第一时间使用$ test($ _ get)值,它显示正确的div,但是on事件由于if条件而无法工作。 If i remove the if condition then it show div A even if the value of the $test is B. how could i handle both.
如果我删除了if条件,那么即使$ test的值是B,它也会显示divA。我该如何处理两者。 Please Help me
请帮我
Shouldn't your JS function be something like: 您的JS函数不应该是这样的:
function enableme() {
if(document.getElementByID('hideme').value == "A") {
if (document.getElementById('div1'))
document.getElementById('div1').style.display = "block";
} else {
if (document.getElementById('div1'))
document.getElementById('div1').style.display = "none";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.