我想做什么?
SWITCH-ON
状态。SWITCH-ON
切换并在页面加载时显示用户信息 (除其他外)我发现了什么?
SWITCH-OFF
状态以及 SWITCH-ON
状态期间复制了 HTML 元素,并注意到一些属性发生了变化。我假设了什么?
SWITCH-OFF
状态更改为 SWITCH-ON
状态将显示隐藏信息。到目前为止我做了什么?
SWITCH-ON
(看) 按钮时,它不会改变状态,然后实际上会显示信息。因此,按预期工作。这就是它的样子:
SWITCH-ON
状态相同,但细节没有透露。
显示代码?
SWITCH-OFF
状态的HTML<!-- OFF SWITCH LOOKS LIKE THIS -->
<div class="next-box custom-switch-selector" style="flex-flow: column; margin: 0px 0px 0px 4px; display: flex;">
<div role="switch" tabindex="0" data-spm="d_buyer_sensitive_switch" data-more="209304361529099_true"
class="next-switch next-switch-off next-switch-small aplus-auto-exp" aria-checked="false"
data-aplus-ae="x38_42bab7ea"
data-spm-anchor-id="Seller_NP.18660942.d_buyer_shipping_address.d_buyer_sensitive_switch.4a904edfouBzrd"
data-aplus-clk="x38_47ece9ab">
<div class="next-switch-btn"></div>
<div class="next-switch-children"
data-spm-anchor-id="Seller_NP.18660942.d_buyer_sensitive_switch.i0.4a904edfouBzrd"></div>
</div>
</div>
SWITCH-ON
状态的HTML<!-- ON SWITCH LOOKS LIKE THIS -->
<div class="next-box custom-switch-selector" style="flex-flow: column; margin: 0px 0px 0px 4px; display: flex;">
<div role="switch" tabindex="0" data-spm="d_buyer_sensitive_switch" data-more="209304361529099_false"
class="next-switch next-switch-on next-switch-small aplus-auto-exp" aria-checked="true"
data-aplus-ae="x38_42bab7ea"
data-spm-anchor-id="Seller_NP.18660942.d_buyer_shipping_address.d_buyer_sensitive_switch.4a904edfouBzrd"
data-aplus-clk="x38_47ece9ab">
<div class="next-switch-btn" data-spm-anchor-id="Seller_NP.18660942.d_buyer_sensitive_switch.i1.4a904edfouBzrd">
</div>
<div class="next-switch-children"
data-spm-anchor-id="Seller_NP.18660942.d_buyer_sensitive_switch.i0.4a904edfouBzrd"></div>
</div>
</div>
attribute-change
断点时,它会在此函数处中断var n = function(t, e, n) {
if (t && t.setAttribute)
try {
t.setAttribute(e, n)
} catch (t) {}
};
Chrome 显示变量 t、e、n 的以下上下文
t = div.next-switch.next-switch-on.next-switch-small.aplus-auto-exp {__reactInternalInstance$h4n036gxgak: bi, __reactEventHandlers$h4n036gxgak: {…}, checked: true, align: '', title: '', …}, e = "data-spm-anchor-id", n = "Seller_NP.18660942.d_buyer_shipping_address.d_buyer_sensitive_switch.4a904edfouBzrd"
上面代码部分的整个js文件被给出为a fiddle here
最后,这是一个你可以尝试的小提琴。
const orderno = 209386708264213;
const custSwitchselector = document.getElementsByClassName("next-box custom-switch-selector")[0];
const custSwitch = custSwitchselector.getElementsByClassName("next-switch")[0];
// Modify Attributes of Div from OFF to ON state
custSwitch.setAttribute("aria-checked", true);
custSwitch.setAttribute("data-more", orderno + '_false');
custSwitch.setAttribute("class", 'next-switch next-switch-on next-switch-small aplus-auto-exp');
//Store Anchor value
const anchor = custSwitch.getAttribute("data-spm-anchor-id");
const frontanchor = 'Seller_NP.18660942.d_buyer_shipping_address.d_buyer_sensitive_switch.'
var endanchor = anchor.replace(frontanchor, "").trim();
//Create Anchors for Button and Child
nextSwitchbutton = custSwitch.getElementsByClassName("next-switch-btn")[0];
nextSwitchchild = custSwitch.getElementsByClassName("next-switch-children")[0];
switchbuttonAnchor = frontanchor
switchbuttonAnchor += "i1."
switchbuttonAnchor += endanchor
switchchildAnchor = frontanchor
switchchildAnchor += "i0."
switchchildAnchor += endanchor
// Modify Attributes of Button and Children
nextSwitchbutton.setAttribute("data-spm-anchor-id", switchbuttonAnchor)
nextSwitchchild.setAttribute("data-spm-anchor-id", switchchildAnchor)
//At this point SWITCHED-OFF switch is IDENTICAL to SWITCHED-ON switch
// But the Details are not revealed
//
// Is there a way to simulate the toggle of the switch on page open?
<!DOCTYPE html>
<html>
<head>
<!-- The Bootstrap used for the styling is Next js and Next css based -->
<link rel="stylesheet" href="https://g.alicdn.com/code/npm/@alife/aidc-fusion-theme/3.26.11/DARAZ/next.min.css" />
<script src="https://g.alicdn.com/code/npm/@alife/aidc-fusion-theme/3.26.11/DARAZ/next.min.js"></script>
</head>
<body>
<!-- Example of Switched OFF Switch -->
<div class="next-box custom-switch-selector" style="flex-flow: column; margin: 0px 0px 0px 4px; display: flex;">
<div role="switch" tabindex="0" data-spm="d_buyer_sensitive_switch" data-more="209304361529099_true" class="next-switch next-switch-off next-switch-small aplus-auto-exp" aria-checked="false" data-aplus-ae="x38_42bab7ea" data-spm-anchor-id="Seller_NP.18660942.d_buyer_shipping_address.d_buyer_sensitive_switch.4a904edfh1RhSk"
data-aplus-clk="x38_47ece9ab">
<div class="next-switch-btn" data-spm-anchor-id="Seller_NP.18660942.d_buyer_sensitive_switch.i0.4a904edfh1RhSk">
</div>
<div class="next-switch-children"></div>
</div>
</div>
</body>
</html>
这太愚蠢了,但答案是
document.getElementsByClassName("next-switch-children")[0].click()
我从来没有想到可以简单地模拟点击。尽管很容易解决这个问题,但还是写下了这个答案,以将其他人从这个泥潭中拯救出来。
谢谢你,詹姆斯