[英]clickable div tag
Im trying to make my div tag clickable, but i cant find out whats the problem. 我试图使我的div标签可点击,但我找不到问题所在。 Its a five star rating system, where the stars is giving different values.
它是五星级评级系统,其中的星星给出不同的值。 from 1 to 5.
从1到5。
On mouse over div tag is changing image, but wont give me any result when clicking. 在div上的鼠标悬停标签正在更改图像,但单击时不会给我任何结果。
my div tag 我的div标签
<div id="5" OnClick="SendRating(value);" onmouseover=rateStar(id) value="5" ><img src="star.jpg"></div>
function rateStar(rating){
var i = 1;
var ratings = '';
for (i==1; i<=5; i++){
if (i<=rating){
document.getElementById(i).innerHTML = '<img src=\"star1.gif\">';
}
else{
document.getElementById(i).innerHTML = '<img src=\"star.jpg\">';
}
}
}
And this is my sendrating function 这是我的sendrating函数
function SendRating(RatingValue){
var paramas = "rating="+RatingValue;
$.ajax({
type: "POST",
url: "rating.php",
data: paramas,
success: function(responseText)
{
document.getElementById("ContentHolder").innerHTML = responseText;
}
}
);
}
onclick
you call the function SendRating
with one argument — value
— but you never define that variable. onclick
会使用一个参数( value
调用函数SendRating
,但是您永远不会定义该变量。
You also have a number of errors in the HTML, you should validate it . HTML中还存在许多错误,您应该对其进行验证 。
get the star rating value from the id and use it like this 从ID中获取星级评分值,并像这样使用它
<script type="text/javascript">
function clicked(item) {
alert($(item).attr("id"));
}
</script>
<div onclick="sendRating(this);" id="5">test</div>
you can also try using the following 您也可以尝试使用以下内容
<div id="3" onClick="sendRating(this.id)">B3</div>
<script type="text/javascript">
function sendRating(id)
{
alert(id);
}
</script>
for (i==1; i<=5; i++){
should be: 应该:
for (var i=1; i<=5; i++){
and, OnClick
should be all lowercase, 并且,
OnClick
应该全部小写,
As stated earlier the HTML cannot find your JavaScript function. 如前所述,HTML无法找到您的JavaScript函数。 But also note that you have not nested in the JS funciton inside <script type="text/javascript">...</script> tags.
但也请注意,您没有嵌套在<script type =“ text / javascript”> ... </ script>标记内的JS函数中。 So the function declaration is interpreted by the browser as text, and not as JavaScript.
因此,浏览器会将函数声明解释为文本,而不是JavaScript。
Some tips on the HTML: All attributes should be lower-case, and their value should be inside double-quotes. HTML上的一些技巧:所有属性都应为小写,并且其值应在双引号内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.