我正在尝试获取不同的元素ID并为每个元素设置工具提示但我无法做到
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
var data = {
name: "enter your name",
family: "enter your family",
testfamily: "enter your family",
uc1_txtname: "enter your name for Control 1 (User Control1)",
uc2_txtname: "enter your name for Control 2 (User Control2)"
}
function tooltipshow() {
//trying to get different element id and set tooltip, the below code is just a sample
document.getElementbyID(dynamicID).Title = "DynamicTooltip based on element ID";
}
};
答案 0 :(得分:3)
function tooltipshow(ID, tooltip) {
document.getElementById(ID).setAttribute('title', tooltip);
}
for (item in data) {
if (data.hasOwnProperty(item)) {
tooltipshow(item, data[item]);
}
}