开发者

Changing input element value in the fly

I'm trying to create a voting system. So when the user clicks the "Vote" button, I want to display the vote count alongside which reflects the count in real time.

I'm using a code something like

HTML

<div class='left'>
    <input id='vote' name='voteCount' type='button' value='1' />
</div>

JavaScript

$.ajax({
    type: "POST",
    url: "vote.php",
    data: dataPass,
    cache: false,
    success: function(html){
        $("#vote").val() = count;
    }
});

I'm using the input button to display the vote count since I think it's easier for me to get the button value using jQuery .val() (which is going to be the vote count at pr开发者_开发技巧esent) then increment it when a user votes it and display the vote count simply by setting the new value as the value of the button.

However, the above codes doesn't seen to work. The value doesn't update after setting it. So can anyone tell me what's the best way to display the vote count in real time?


For setting the value the syntax is

$("#vote").val(count);


There may be other problems, but the jQuery val() function expects you to pass the value as an argument, like the following

$("#vote").val(count);

Instead of

$("#vote").val() = count;


You need to put the value as an an argument to val:

.val(count)


val method take the new value as argument, you can't assign it like this.
So:

$("#vote").val(count);

And you'll have to calculate that count of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜