.val() 选择文本而不是值字符串,当网页动态编辑源 html
.val() select text instead the value string when the webpage dinamically edits the source html
我在网页上有这个html:
<select name="chapter_select" class="chapter_select">
<option value="http://www.example.com/chapter/1">Chapter 1</option>
<option value="http://www.example.com/chapter/2">Chapter 2</option>
<option value="http://www.example.com/chapter/3">Chapter 3</option>
<option value="http://www.example.com/chapter/4">Chapter 4</option>
<option value="http://www.example.com/chapter/5">Chapter 5</option>
<option value="http://www.example.com/chapter/6" selected="selected">Chapter 6</option>
</select>
而这个变量:
getInformationsFromCurrentPage : function(doc, curUrl, callback) {
//This function runs in the DOM of the current consulted page
var curChapName = $("select.chapter_select:first option:selected", doc).text();
var chapurl = $("select.chapter_select:first option:selected", doc).val();
callback({"name": name,
"currentChapter": curChapName,
"currentMangaURL": nameurl,
"currentChapterURL": chapurl});
},
}
问题是两者都返回相同的文本值。 Chapurl 应该返回 URL,而不是文本值。这一直有效,直到网站修改了他们的网站。
我知道我会很挑剔,但这是开发扩展的手册,文档变量是必须的 http://www.allmangasreader.com/dev.php 只需注意getInformationsFromCurrentPage函数。它使用的是jQuery 1.4.2,所以也许是这样,奇怪的是其他网站只是像它一样工作。
更新:服务器正在使用脚本(重写html),使我认为下拉列表位于顶部。我使用了一些选择器来获得遵循源的正确选择器。
var curChapName = $("select.chapter_select:first option:selected", doc).text();
var chapurl = $("select.chapter_select:first option:selected", doc).val();
这项工作 http://jsfiddle.net/所以你的 doc 变量一定有问题,请检查它
总是可以使用回退并使用 attr。这样,您始终可以保证您将获得价值。
var chapval = $("select.chapter_select:first option:selected").attr('value');
http://jsfiddle.net/dt5PV/
var curChapName = $("select.chapter_select:first :selected").text()
var chapurl = $("select.chapter_select:first").val()
相关文章:
- 如何在不重新加载整个网页的情况下动态更改经度和纬度的值
- I'我试图在我的网页上动态地上下移动元素.我该怎么做
- Matplotlib;动态网页
- 使用htmlunit抓取动态网页
- 从脚本中的动态(javascript)网页获取信息
- 如何使用javascript在asp.net网页表单上动态添加文本框
- 如何为动态网页创建谷歌放大器
- .val() 选择文本而不是值字符串,当网页动态编辑源 html
- 使用 jQuery 将文本框动态添加到网页
- 使用 HTML5<输入>字段抓取动态生成的网页
- 动态网页的SEO
- 在不增加分析跳出率的情况下,绑定网页上的内部链接以动态加载
- 从动态生成的列表在PHP网页之间传递数据
- 使用javascript/jquery从网页中获取动态更改的数据
- 动态网页的快捷方式
- 动态创建的网页不起作用
- 在网页上动态更改图像,而无需先将它们存储在服务器中[Javascript/Jquery - Spring]
- 动态突出显示(更改背景)/网页中的内容
- 使用用户脚本记录网页动态创建的标记属性
- 使用用户脚本记录网页动态创建的 DOM 元素