**mui('#list').on('tap', 'a', function() {
var id = this.getAttribute('href');
var type = this.getAttribute("open-type");
if (type == "common") {
if (~id.indexOf('')) {
var pop = ~id.indexOf('offcanvas-with-right') ? "close" : "none";
mui.openWindow({
id: id,
url: this.href,
styles: {
zindex: 9999,
popGesture: pop
},
waiting: {
autoShow: false
}
});
} else {
alert(222);
mui.openWindow({
id: id,
url: this.href,
waiting: {
autoShow: false
}
});
}
} else {
//如何获取指定id的对象呢?
var moviename = this.getElementById("moviename");
alert("获取的id值"+moviename);
if (id && ~id.indexOf('.html')) {
var href = this.href;
//获得共用模板组
var template = ~href.indexOf('pullrefresh.html')?getTemplate('pullrefresh'):getTemplate('default');
//判断是否显示右上角menu图标;
var showMenu = ~href.indexOf('popovers.html')?true:false;
//获得共用父模板
var headerWebview = template.header;
//获得共用子webview
var contentWebview = template.content;
var title = this.innerText;
//通知模板修改标题,并显示隐藏右上角图标;
mui.fire(headerWebview,'updateHeader',{title:title,showMenu:showMenu});
var reload = true;
if (!template.loaded) {
if (contentWebview.getURL() != this.href) {
contentWebview.loadURL(this.href);
} else {
reload = false;
}
} else {
reload = false;
}
(!reload) && contentWebview.show();
headerWebview.show('slide-in-right', 150);
}
}
});
**
应用HBuilder已启动...
Uncaught ReferenceError: mui is not defined
Uncaught ReferenceError: mui is not defined
Uncaught ReferenceError: mui is not defined
Uncaught TypeError: Object [object HTMLAnchorElement] has no method 'getElementById' at cinema.html:296
Uncaught TypeError: Object [object HTMLAnchorElement] has no method 'getElementById' at cinema.html:296
2 个回复
bxh201
先说为什么报错吧. 你的this是a啊。a是没有getElementById这个方法的。
DCloud_UNI_FXY
document. getElementById
txfyteen (作者)
<div class="mui-content">
<ul id="list" class="mui-table-view mui-table-view-chevron">
<div class="title">附近影院</div>
<li class="mui-table-view-cell">
<a id="_item1" href="cinemaInfo.html">
<div >
<img class="mui-media-object mui-pull-right" src="images/tip_zuo.png">
</div>
<div >
<span id="moviename">广东五月花电影城</span>
<p class="mui-ellipsis">广州市中山五路68号五月花商业广场6-7楼</p>
</div>
</a>
</li>
<li class="mui-table-view-cell mui-media">
<a href="cinemaInfo1.html">
<img class="mui-media-object mui-pull-right" src="images/tip_zuo.png">
<div class="mui-media-body">
<span id="moviename">广州横店影城</span>
<p class='mui-ellipsis'>广州市天河区长兴路13号高德汇购物广场三楼</p>
</div>
</a>
</li>
<ul>
<div>
我是想获取的是li里面的那个span的值传递到下一个子页面的,之前是通过this.getElementById("moviename"),这里的this不是指的是li这一块里面找moviename的id吗?如果不是this不是值li这一块,我还有一个问题想问,以后我ul的数据是要遍历的,我想在li里面去查找指定的id这个要怎么写呢?(本人js基础不是很好,谢谢了)
2015-01-05 13:57
DCloud_UNI_FXY
标签中的id属性,在整个html中应该是唯一的。你不应该在一个html页面有很多个相同的id。
想找到li里的span很容易,直接this.querySelector('span')即可。
2015-01-05 13:59