我有以下html:
<div type="Text with spaces" eventid="57" class="movie">...</div>
如何使用jQuery读取type
属性?
我试过了:
var type = $(".movie").attr("type");
但type
仅包含Text
。
更新
这就是我使用这个变量的方式:
$("#publicationBlock").load("/Publication/EventSchedule?eventId=" + eventId + "&type=" + type
在动作中,我只获得Text
。
答案 0 :(得分:1)
应该有用。
var type=$(".movie").attr("type");
alert(type);
fiddle此处..
看看你是否错过了这个
1)确保您的代码在准备好的函数$(function(){
内
2)检查jquery版本..最新更好
<强>更新强>
<div type="Text_with_spaces" eventid="57" class="movie">...</div>
并在EventSchedule
函数
答案 1 :(得分:0)
我在这里没有看到问题?
此示例与您的代码完全相同,但它能够显示整个属性:http://jsfiddle.net/rFYpE/
var type = $(".movie").attr("type");
alert(type);
你是如何使用变量类型的?