无法从 UL 中的每个 LI 中选择和收集文本。请看我到目前为止的例子,http://jsfiddle.net/Twisty/YYbfY/
HTML
<div data-role="navbar" data-mini="true">
<ul id="resultHeader">
<li><span class='ui-btn ui-btn-inline ui-btn-up-b'><span class='ui-btn-inner'>Column A</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-b'><span class='ui-btn-inner'>Column B</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-b'><span class='ui-btn-inner'>Column C</span></span></li>
</ul>
<ul class='resultRow'>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d' title='mack5.com.'><span class='ui-btn-inner'>Item 1</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 2</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 3</span></span></li>
</ul>
<ul class='resultRow'>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d' title='mack5.com.'><span class='ui-btn-inner'>Item 1</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 2</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 3</span></span></li>
</ul>
<ul class='resultRow'>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d' title='mack5.com.'><span class='ui-btn-inner'>Item 1</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 2</span></span></li>
<li><span class='ui-btn ui-btn-inline ui-btn-up-d'><span class='ui-btn-inner'>Item 3</span></span></li>
</ul>
</div>
<textarea id="clipText-cell"></textarea>
<textarea id="clipText-row"></textarea>
<textarea id="clipText-all"></textarea>
<div id="copyPopup" data-role="popup" data-positionTo="origin">
<div data-role="controlgroup" data-mini="true">
<a href="" data-role="button" id="copyCell-btn">Copy '<span id="copyCellBtn-text"></span>'</a>
<a href="" data-role="button" id="copyRow-btn">Copy Row</a>
<a href="" data-role="button" id=copyAll-btn>Copy All Rows</a>
</div>
</div>
查询
var tapTimer, isTapHold = false;
$(".resultRow li").bind("vmousedown vmouseup", function(e) {
var clickedLi = $(this).parent().parent("li");
var clickedUl = clickedLi.parent("ul");
var cellText = $(this).text();
var rowText = "";
var tableText = "";
var rows = [];
var table = [];
if (e.type == "vmousedown") {
tapTimer = setTimeout(function() {
isTapHold = true;
//alert("Click-Hold for 1.5 seconds.");
$("#copyCellBtn-text").html(cellText);
$("#clipText-cell").val(cellText);
$("#clipText-row").val(rowText);
$("#clipText-all").val(tableText);
$("#copyPopup").popup("open", {
x: (e.pageX + 100),
y: (e.pageY + 60)
});
}, 1500);
} else {
// e.type = 'vmouseup'
// Clear the timeout if not already reached
clearTimeout(tapTimer);
// if flag is set to false, regular tap or click
if (!isTapHold) {
// Not Click-Hold, do nothing
}
// Reset flag
isTapHold = false;
}
});
我想要发生的是当用户点击或点击按住时,会出现一个弹出菜单,他们可以在其中选择复制他们点击的文本、整行的文本或整个表格的文本。
为了收集行数据,我试图弄清楚如何遍历被点击li
的每个,ul
并收集相应的所有文本textarea
。一旦我能得到这个,我就可以创建一个循环来对所有的ul
's 做同样的事情,以便以后收集所有的文本。