小编for*_*tso的帖子

覆盖困难的视图模型

我试图使用JS替换输入字段中的一些文本,但视图模型每次都会覆盖我的命令.这是我开始的HTML:

<td class="new-variants-table__cell" define="{ editVariantPrice: new Shopify.EditVariantPrice(this) }" context="editVariantPrice" style="height: auto;">
    <input type="hidden" name="product[variants][][price]" id="product_variants__price" value="25.00" bind="price" data-dirty-trigger="true">
    <input class="mock-edit-on-hover tr js-no-dirty js-variant-price variant-table-input--numeric" bind-event-focus="onFocus(this)" bind-event-blur="onBlur(this)" bind-event-input="onInput(this)">
</td>
Run Code Online (Sandbox Code Playgroud)

我运行这个JS:

jQuery('#product_variants__price').siblings().removeAttr('bind-event-focus');
jQuery('#product_variants__price').siblings().removeAttr('bind-event-input');
jQuery('#product_variants__price').siblings().removeAttr('bind-event-blur');
jQuery('#product_variants__price').siblings().focus()
jQuery('#product_variants__price').siblings().val("34.00");
jQuery('#product_variants__price').val("34.00");
Run Code Online (Sandbox Code Playgroud)

我留下了以下HTML:

<td class="new-variants-table__cell" define="{ editVariantPrice: new Shopify.EditVariantPrice(this) }" context="editVariantPrice" style="height: auto;">
    <input type="hidden" name="product[variants][][price]" id="product_variants__price" value="34.00" bind="price" data-dirty-trigger="true">
    <input class="mock-edit-on-hover tr js-no-dirty js-variant-price variant-table-input--numeric">
</td>
Run Code Online (Sandbox Code Playgroud)

问题是,每次单击输入字段时,该值都将恢复为页面加载时的值.

我也尝试在父td中运行命令以及我的值更改,以模拟变体的编辑并防止默认但没有成功:

jQuery('#product_variants__price').siblings().bind('input', function (e) {
    e.preventDefault();
    return false;
});
jQuery('#product_variants__price').siblings().bind('focus', function (e) {
    e.preventDefault();
    return false;
});
jQuery('#product_variants__price').siblings().focus()
jQuery('#product_variants__price').siblings().val("£34.00"); …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery shopify

17
推荐指数
1
解决办法
375
查看次数

Tab键在chrome扩展名的弹出窗口中不起作用

我创建了一个chrome扩展,其中包含一个带有以下HTML标记的弹出窗口:

<html>
<head>
<style>
body {
font-family: 'Open Sans',arial,sans-serif;
background-color: #E5E5E5;
font-size: 13px;
text-shadow: 0px 1px rgba(255, 255, 255, 0.5);
}
</style>
</head>
<script type="text/javascript">function sendRequest(s,r){
chrome.tabs.getSelected(null, function(tab) {
  chrome.tabs.sendRequest(tab.id, {search:s , replace:r}, function(response) {
    console.log(response.farewell);
  });
});
};
</script>
<body>

<label for="search">Search for</label><input name="search" id="search"></input>
<label for="replace">Replace with</label><input name="replace" id="replace"></input>
<button onclick="var s=document.getElementById('search').value;var r=document.getElementById('replace').value;sendRequest(s,r);">Go</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我打开弹出窗口时,选择第一个输入字段,然后按Tab键,输入字段失去焦点,但第二个输入字段没有获得焦点.

如果我再次选择第一个并再次按Tab键,则第二个字段会获得焦点.再次按下可使按钮获得焦点,第三次按下可使第一个场再次获得焦点.

有谁知道为什么第一个按键按键不起作用?

google-chrome popup tabbing google-chrome-extension

9
推荐指数
1
解决办法
1901
查看次数