简体   繁体   English

可点击的div标签

[英]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.

相关问题 锚标签无法使div可点击 - anchor tag in not making div clickable jQuery / CSS-Whole Div Clickable,悬停时激活标签悬停状态 - jQuery/CSS - Whole Div Clickable, on hover activate a tag hover state 如何在不单击 div 的情况下单击可点击 div(ng-click)内的标签? - How can I click a tag inside of clickable div(ng-click) without clicking the div? 锚定标签不可点击,<a>标签</a>上方的可点击区域 - Anchor tag not clickable, clickable area over the <a> tag 使div具有<a>clickable,</a>使div <a>不具有</a> <a>非clickable</a> - make div with <a> clickable and div with no <a> non clickable 让父div可点击,可点击子div - have parent div clickable with clickable child div <a>标签</a>内的可点击元素 - Clickable element inside <a> tag 如何使用“react-router-dom”中的“链接”使“div”标签可点击? - How to make "div" tag clickable with "Link" from "react-router-dom"? 如何在可单击的 div 标签中放置文本超链接,以便在单击时仅触发超链接 - How can I place a text hyperlink in a clickable div tag such that only the hyperlink is triggered when clicked 如何在DIV标签上使用javascript onclick来切换包含可点击链接的部分的可见性? - How to use javascript onclick on a DIV tag to toggle visibility of a section that contains clickable links?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM