我无法将此代码的最后一行的值变为静态的。我需要它进行硬编码,因此当他们下拉菜单并选择时,它会获取该值并将其放入动作脚本中。
任何帮助?
<select id="yo5" onChange="asdf90()"><option>// Let the Page Refresh for each Pick Please!</option>
<option id="yo4" value="<?php echo $test1 ?>"><?php echo $test1 ?></option>
<option value="<?php echo $test2 ?>"><?php echo $test3 ?></option>
<option><?php echo $test4 ?></option>
<option><?php echo $test5 ?></option>
<option><?php echo $test6 ?></option>
<option><?php echo $test7 ?></option>
<option><?php echo $test8 ?></option>
<option><?php echo $test9 ?></option>
<option><?php echo $test10 ?></option>
</select>
<script type = "text/javascript">
function asdf90()
{
elem = <?php $test1 ?>;
if(document.getElementById('yo5').value = elem)
{
alert('hi');
}
}
</script>
<form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
<div id="nonexsist4"><input name="blog[domain]" type="hidden" value="" /></div>
答案 0 :(得分:1)
在你的echo语句之后放置分号..
<option><?php echo $test9; ?></option>
并使用==
运算符,而不是=
if(document.getElementById('yo5').value == elem)
答案 1 :(得分:0)
代码有几个错误。我引用了正确的代码:
<select id="yo5" onChange="asdf90()">
<option id="yo4" value="<?php echo $test1; ?>"><?php echo $test1; ?></option>
<option value="<?php echo $test2; ?>"><?php echo $test3; ?></option>
<option><?php echo $test4; ?></option>
<option><?php echo $test5; ?></option>
<option><?php echo $test6; ?></option>
<option><?php echo $test7; ?></option>
<option><?php echo $test8; ?></option>
<option><?php echo $test9; ?></option>
<option><?php echo $test10; ?></option>
</select>
<script type = "text/javascript">
function asdf90()
{
var elem = "<?php echo $test1; ?>";
if(document.getElementById('yo5').value == elem)
{
alert('hi');
}
}
</script>
问候