是javascript的新手。函数changeStuff仅执行一次(在文档准备好之后),但其他onchange事件不起作用。我想根据选择输入中的值来更改显示或隐藏哪些元素。这是代码。
'أ»آ'أôقÄûأ»آ٤أ»آ١أôقÄöأôإ أ»آ)'
sqlContext = SQLContext(sc)
df = sqlContext.read.format("jdbc").options(
url="jdbc:mysql://localhost/db_name",
driver="com.mysql.jdbc.Driver",
dbtable="table",
user="root",
password="root"
).load()
df.show()
我先前遇到的一个问题是,当我将每个文档对象分配给一个变量以减少我编写的代码时,html文件在浏览器中以null形式打开,并出现错误`$sql = "INSERT INTO matches (comp_id, matchdate, matchtime, hometeam, awayteam) VALUES ('".$_POST["comp_id"]."', '".$_POST["matchdate"]."', '".$_POST["matchtime"]."', '".$_POST["hometeam"]."', '".$_POST["awayteam"]."')";
$result1 = $conn->query($sql);
$sql1 = "INSERT INTO results (comp_id, hometeam, awayteam) VALUES ('".$_POST["comp_id"]."', '".$_POST["hometeam"]."', '".$_POST["awayteam"]."')";
$result2 = $conn->query($sql1);
// Execute the query
if ($result1 && $result2) {
echo "<script>alert('Record Updated Successfully')</script>";
header("refresh:1; url=insert-comp.php");
} else {
echo "<script>alert('Database Not Updated')</script>";;
}
}
`
,我对此进行了转义重复function changeStuff() {
if (document.getElementById('editLocation').value == 'Resident') {
document.getElementById('editResidentZoneDiv').style.display = 'block';
document.getElementById('editNonResidentZoneDiv').style.display = 'none';
document.getElementById('editKmZoneDiv').style.display = 'none';
document.getElementById('editNonResidentZone').removeAttribute('required');
document.getElementById('editKmZone').removeAttribute('required');
} else if (document.getElementById('editLocation').value == 'Non-Resident') {
document.getElementById('editResidentZoneDiv').style.display = 'none';
document.getElementById('editNonResidentZoneDiv').style.display = 'block';
document.getElementById('editKmZoneDiv').style.display = 'none';
document.getElementById('editResidentZone').removeAttribute('required');
} else {
document.getElementById('editResidentZoneDiv').style.display = 'none';
document.getElementById('editNonResidentZoneDiv').style.display = 'none';
document.getElementById('editKmZoneDiv').style.display = 'none';
}
if (document.getElementById('editNonResidentZone').value == 'KM') {
document.getElementById('editKmZoneDiv').style.display = 'block';
} else {
document.getElementById('editKmZoneDiv').style.display = 'none';
}
}
if (document.readyState == 'complete') {
document.body.addEventListener('load', changeStuff())
}
document.getElementById('editLocation').addEventListener('change', changeStuff())
document.getElementById('editResidentZone').addEventListener('change', changeStuff())
document.getElementById('editNonResidentZone').addEventListener('change', changeStuff())
document.getElementById('editKmZone').addEventListener('change', changeStuff())
。请帮助我解决事件问题。
答案 0 :(得分:3)
将您所有的addEventListsener
代码更改如下:
document.getElementById('editLocation').addEventListener('change', changeStuff)
应为changeStuff
而不是changeStuff()
使用()
,将在文档准备就绪后立即调用该函数。
答案 1 :(得分:0)
document.getElementById('editLocation')。addEventListener('change',changeStuff) document.getElementById('editResidentZone')。addEventListener('change',changeStuff) document.getElementById('editNonResidentZone')。addEventListener('change',changeStuff) document.getElementById('editKmZone')。addEventListener('change',changeStuff)
这应该可以工作...