我是想实现我的Django管理一个javascript代码,我有两个字段hard_drives(id为:id_hard_drives
)和no_of_drives(id为:id_no_of_drives
)。所以,我想no_of_drives出现只有hard_drives具有特殊的价值,像例如:意外标记<在JS
<script type="text/javascript">
$("#id_hard_drives").change(function() {
if($("#id_hard_drives").val()=="125"){
document.getElementById("#id_no_of_drives").type=text
} else {
document.getElementById("#id_no_of_drives").type=hidden
}
});
</script>
但是,我得到一个错误:
Unexpected token <
更新:
根据GSWV,我已更新的代码,但它仍然用来显示相同的错误,所以我删除<script>
标签。新的代码看起来是这样的:
(function($) {
$(document).ready(function() {
var hardDriveSelector = $("#id_hard_drives");
hardDriveSelector.on("change", function(){
if (hardDriveSelector.val() == "H") {
document.getElementById("id_no_of_drives").type = text;
} else {
document.getElementById("id_no_of_drives").type = hidden;
}
});
});
})(django.jQuery);
但代码不被飞实施,脚本这么想的做任何事情,我需要使用钥匙向上或某事上id_hard_drives
?
使用语法hilighting和Linter获取编辑器。请参阅:http://stackoverflow.com/questions/6803305/should-i-use-jslint-or-jshint-javascript-validation $(“。#id_hard_drives”)。change(function(){ \t if($ ( “#id_hard_drives”)VAL()== 125){ \t \t的document.getElementById( “id_no_of_drives”)类型=文本; \t}。 \t否则{ \t \t文档。getElementById(“id_no_of_drives”)。type = hidden; \t} }); – digitaldonkey
欢迎来到Stack Overflow!我编辑了你的问题,删除了谢谢和其他句子,因为没有必要。 – jezrael