提取网页javascript中的字段值
Extract field value present in javascript of a webpage
这是html网页中的脚本。
jQuery(function($) {
new Shopify.OptionSelectors('productSelect', {
product: {
"id":626976579,
"title":"changedMacbook Air",
"handle":"macbook-air",
"description":"'u003cp'u003elightweight 'u003c'/p'u003e'n'u003cp'u003eawesome performance'u003c'/p'u003e'n'u003cp'u003ewow display'u003c'/p'u003e'nHello World626976579['"78000.00'"] ['"78000.00'"]''n['"78000.00'"] ['"78000.00'"]'u003cbr'u003e['"78000.00'"]'u003cbr'u003e626976579'u003cbr'u003e626976579'u003cbr'u003e626976579",
"published_at":"2015-05-25T02:39:00-04:00",
"created_at":"2015-05-25T02:40:44-04:00",
"vendor":"Test_Store",
"type":"Computers",
"tags":[],
"price":7800000,
"price_min":7800000,
"price_max":7800000,
"available":true,
"price_varies":false,
"compare_at_price":null,
"compare_at_price_min":0,
"compare_at_price_max":0,
"compare_at_price_varies":false,
"variants":[{"id":1754837635,"title":"Default Title","options":["Default Title"],"option1":"Default Title","option2":null,"option3":null,"price":7800000,"weight":800,"compare_at_price":null,"inventory_quantity":-29,"inventory_management":null,"inventory_policy":"deny","available":true,"sku":"20","requires_shipping":true,"taxable":true,"barcode":"","featured_image":null}],"images":["'/'/cdn.shopify.com'/s'/files'/1'/0876'/1234'/products'/overview_wireless_hero_enhanced.png?v=1432536113"],"featured_image":"'/'/cdn.shopify.com'/s'/files'/1'/0876'/1234'/products'/overview_wireless_hero_enhanced.png?v=1432536113","options":["Title"],"content":"'u003cp'u003elightweight 'u003c'/p'u003e'n'u003cp'u003eawesome performance'u003c'/p'u003e'n'u003cp'u003ewow display'u003c'/p'u003e'nHello World626976579['"78000.00'"] ['"78000.00'"]''n['"78000.00'"] ['"78000.00'"]'u003cbr'u003e['"78000.00'"]'u003cbr'u003e626976579'u003cbr'u003e626976579'u003cbr'u003e626976579"},
onVariantSelected: selectCallback,
enableHistoryState: true
});
如何通过我自己的JavaScript访问"title"字段的值,这里是"changedMacbookAir"?
提前谢谢。
我不知道它是否有效,但尝试
var myProduct = new Shopify.OptionSelectors('productSelect', {
....
})
然后尝试
console.log(myProduct)
或者你可以试试这个:
$(document).ready(function(e){
console.log(document.title);
})
我认为您可能必须通过回调传递它。
$('#productSelect').on('change', function(e) {
var t = e.target || e.srcElement,
title = t.title.value;
selectCallback(title);
break;
}
}
});
//If you want to trigger it right away for some reason, just use this...
$("#productSelect").change();
在产品模板或代码段、资产或模板中查找option_selection.js的代码。请参阅此fiddle以获取代码外观的示例。option_selection.js
你可能还想查看这个链接,它正在为产品变体设置一个onchange事件。我不确定你的最终目标是什么,但我看到你正在处理产品选项和变体,所以这可能会有所帮助。
如果需要,您可以修改option_selection.js,但很可能您只需要在document.ready.中进行一些jquery
下面是option_selection.js中的一个示例,它构建了每个选择器的名称。虽然您可能不需要对此进行修改,但请参阅上面的链接。
Shopify.OptionSelectors.prototype.buildSelectors = function() {
for (var t = 0; t < this.product.optionNames().length; t++) {
var e = new Shopify.SingleOptionSelector(this, t, this.product.optionNames()[t], this.product.optionValues(t));
e.element.disabled = !1, this.selectors.push(e)
}
var o = this.selectorDivClass,
i = this.product.optionNames(),
r = Shopify.map(this.selectors, function(t) {
var e = document.createElement("div");
if (e.setAttribute("class", o), i.length > 1) {
var r = document.createElement("label");
r.htmlFor = t.element.id, r.innerHTML = t.name, e.appendChild(r)
}
return e.appendChild(t.element), e
});
return r
},
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 而循环只设置php中输入字段中的第一个值
- 在输入字段中将最小金额设置为
- 使用 HTML5<输入>字段抓取动态生成的网页
- 从数据库创建可单击列表,并在网页元素中返回相关的数据库字段数据
- 网页过滤器表单.Javascript 不允许使用多个字段
- Google Maps JavaScript API v3 - 在iPhone上查看的网页上的自动完成字段不存储值,不返
- 使用 Jquery 通过 Chrome 扩展程序更改网页中的字段值
- 如何为网页上的指定输入字段关闭iPhone键盘
- 如何通过UI启用/禁用struts2网页中的强制字段
- javascript表单(html网页)名称字段的验证
- 尝试在谷歌网页设计与自定义javascript创建动画动态字段
- 如何根据输入字段动态更改网页内容
- 显示搜索字段时,有些人开始在网页上输入
- 通过URL预填充网页字段
- 如何使用JavaScript和jQuery可视化地模拟网页输入字段上的键盘按键
- 当点击时,在注入的侧边栏chrome扩展中的字段内添加网页上的所选文本
- 提取网页javascript中的字段值
- 用户输入字段最好使用 DIV 或表单,用于仅计算公式的网页
- . getelementbyid().值在窗体's隐藏字段asp.net网页中不起作用