我想检查由"h“javascript函数触发的隐藏字段的值。如果它是“空的”,我希望提示用户使用评级表单对我的页面进行评级(从而停留在同一页面并忽略h目标页面。如果值是"rated",我只想让用户前进到他们想要的页面。
以下是我到目前为止开发的一些代码,但并不能很好地工作:
function ratings_prompt(){
var checkIfRated = document.getElementById("hidden_rating");
if (checkIfRated.value == "empty")
{
alert("The Field is set to empty - please rate the form!");
checkIfRated.value=="rated";
}
}编辑:对不起,我似乎不能把所有的代码都放入代码块中。
GF
发布于 2010-08-15 03:01:31
看到更多的代码也帮不上什么忙,而且你也没有说出问题是什么……“没那么好用”是一种vague...but,基本上你会在函数调用的链接中使用"this“引用,你也应该在onclick中返回false;。然后,在您的函数中,如果隐藏字段不为空,则类似于location.href = that.href
<a href='somepage.html' onclick="yourFunction(this);return false;">link</a>
<script type='text/javascript'>
function yourFunction(that) {
if (document.getElementById("hidden_rating").value != "empty") {
location.href = that.href;
} else {
// didn't rate
}
}
</script>https://stackoverflow.com/questions/3484679
复制相似问题