我有这样的HTML:
<a href="javascript:void(0);" id="13" jobtitile="UI Designer (Web Designer / Team Leader)" onclick="postResume(this.id,this.jobtitle);" class="InsideRightBoxLink">Submit Application</a>
java脚本函数是:
function postResume(jobId,jobtitle){
alert(jobtitle);
//alert($("#"+jobId).attr('jobTitle'));
}
两者都是未定义的,请帮助我谢谢。
答案 0 :(得分:1)
<script type="text/javascript">
function postResume(obj){
alert(obj.id);
alert(obj.getAttribute("jobtitile"));
}
</script>
<a href="javascript:void(0);" id="13" jobtitile="UI Designer (Web Designer / Team Leader)"
onclick="postResume(this);" class="InsideRightBoxLink">Submit Application</a>
答案 1 :(得分:1)
jobtitile
不是HTML有效属性,因此请使用getAttribute
函数
更改
this.jobtitile
要
this.getAttribute("jobtitile")
试试此代码
<a href="javascript:void(0);" id="13"
jobtitile="UI Designer (Web Designer / Team Leader)"
onclick="postResume(this.id,this.getAttribute("jobtitile"));"
class="InsideRightBoxLink">Submit Application</a>
答案 2 :(得分:1)
在javascript中获取属性值与jQuery不同。 使用this.getAttribue(&#39; attributeName&#39;);
<a href="javascript:void(0);" id="13" jobtitle="UI Designer (Web Designer / Team Leader)" onclick="postResume(this.id,this.getAttribute('jobtitle'));" class="InsideRightBoxLink">Submit Application</a>
<script>
function postResume(jobId,jobtitle){
alert(jobtitle);
//alert($("#"+jobId).attr('jobTitle'));
}
</script>