想知道是否可以将全局javascript数组值传递给html标记,特别是在img(title)标记内?将全局javascript数组值传递给HTML标记
基本上想知道如果我能做到这一点:
<img src="_info.gif" height="26" width="37" title=myArray[5]/>
如果是这样,怎么样,如果没有,可人们可能提供其他建议。
谢谢
想知道是否可以将全局javascript数组值传递给html标记,特别是在img(title)标记内?将全局javascript数组值传递给HTML标记
基本上想知道如果我能做到这一点:
<img src="_info.gif" height="26" width="37" title=myArray[5]/>
如果是这样,怎么样,如果没有,可人们可能提供其他建议。
谢谢
不,这是不可能的。我建议你使用javascript设置title属性。为了做到这一点,你需要:
1)添加JavaScript钩子元素。例如CSS类或ID 2)通过钩取得元素,并设置其标题
例子:
document.getElementById("myImage").title = myArray[5];
<img id="myImage" src="_info.gif" height="26" width="37"/>
你还不如使用某种JavaScript库,例如jQuery的或原型
我会做这种方式:
<img id="image-1" src="_info.gif" height="26" width="37" />
<script type="text/javascript">
var image = document.getElementById('image-1');
image.setAttribute('title', myArray[5]);
</script>
也可以这样做:
<img src="_info.gif" height="26" width="37" onload="this.title = myArray[5];" />
为什么?..你想做什么? – Reigel 2010-06-02 08:08:18
知道这会实现什么会很有趣。 – dmp 2010-06-02 08:14:26