在 Apple.com 上使用 javascript 更改下拉选项解决我的午餐问题
Change dropdown options using javascript on Apple.com SOLVE THIS LUNCH ON ME
尝试使用 javascript 更改选定的选项,但由于某种原因不起作用。在互联网上四处寻找解决方案,但找不到。需要帮助 !
要获取源代码,请转到
https://www.apple.com/shop/trade-in,于
"Select your device to get a trade-in estimate"
Select 智能手机,Apple,iPhone XS MAX,Select 是的,状况良好,
Select 框 "Trade in for gift Card".
然后您应该会看到一个表单字段,该死的默认状态选项不会为我动态更改,在控制台中使用 javascript。
现在尝试将控制台中的状态更改为 MA(马萨诸塞州)。
目前默认为 'state'.
第一个解决这顿午餐的人是我,下拉您的 PayPal 电子邮件。
或将您的电子邮件地址发送至 arizona777@gmail.com。谢谢 !
:)
源代码:
<select aria-required="true" aria-describedby="tradeUp.shipping.moduleData.address-state-error"
aria-invalid="false" data-autom="address-field-state" value=""
data-recon-click="binding,actionClick,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseover="binding,actionMouseOver,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseout="binding,actionMouseOut,tradeUp.shipping.moduleData.address.state,binding"
data-recon-input="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-change="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusin="binding,setFocus,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusout="binding,clearFocus,tradeUp.shipping.moduleData.address.state,binding"
id="tradeUp.shipping.moduleData.address-state" required=""
class="form-dropdown form-dropdown-selectnone">
<option value="" selected="true">State</option>
<option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="AS">AS</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="MP">MP</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="US">US</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="VI">VI</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
编辑:
我现在设法进入了提到的对话框。如果您在控制台中执行以下命令,您应该能够将状态更改为 'MA'
ch=new MouseEvent('change', {view:window,bubbles:true});
s=document.getElementById('tradeUp.shipping.moduleData.address-state');
s.value='MA';
s.dispatchEvent(ch);
看起来 bootstrap 周围的 select 盒子需要一个变化事件,我们可以用上面的命令生成它。
经过进一步测试,我发现 {bubbles:true}
足以作为上面代码中的 "option" 参数(您可以省略 view:window
部分)。
如果您在使用不寻常的 id 处理 select
元素时遇到问题:您需要屏蔽其中的 .
字符,否则它们将被解释为表示 class 标识符。因此,selector for document.querySelector()
需要类似于 '#tradeUp\.shipping\.moduleData\.address-state'
.
在下面的几行中,您将找到一种更改 select 元素当前 selection 的方法。在这种情况下,我将其更改为 'MA'.
document.querySelector('#change').addEventListener('click',function(){
document.querySelector('#tradeUp\.shipping\.moduleData\.address-state').innerHTML=
['abc','def','ghi','jki','lmn'].map(function(s){return '<option>'+s+'</option>';}).join('');
})
// in case you wanted to change the value of the
// select programmatically, do the following:
document.querySelector('#tradeUp\.shipping\.moduleData\.address-state').value='MA';
<select aria-required="true" aria-describedby="tradeUp.shipping.moduleData.address-state-error"
aria-invalid="false" data-autom="address-field-state" value=""
data-recon-click="binding,actionClick,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseover="binding,actionMouseOver,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseout="binding,actionMouseOut,tradeUp.shipping.moduleData.address.state,binding"
data-recon-input="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-change="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusin="binding,setFocus,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusout="binding,clearFocus,tradeUp.shipping.moduleData.address.state,binding"
id="tradeUp.shipping.moduleData.address-state" required=""
class="form-dropdown form-dropdown-selectnone">
<option value="" selected="true">State</option><option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="AS">AS</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="MP">MP</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="US">US</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="VI">VI</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
<button id="change">change options</button>
尝试使用 javascript 更改选定的选项,但由于某种原因不起作用。在互联网上四处寻找解决方案,但找不到。需要帮助 !
要获取源代码,请转到 https://www.apple.com/shop/trade-in,于 "Select your device to get a trade-in estimate" Select 智能手机,Apple,iPhone XS MAX,Select 是的,状况良好, Select 框 "Trade in for gift Card".
然后您应该会看到一个表单字段,该死的默认状态选项不会为我动态更改,在控制台中使用 javascript。
现在尝试将控制台中的状态更改为 MA(马萨诸塞州)。 目前默认为 'state'.
第一个解决这顿午餐的人是我,下拉您的 PayPal 电子邮件。 或将您的电子邮件地址发送至 arizona777@gmail.com。谢谢 ! :)
源代码:
<select aria-required="true" aria-describedby="tradeUp.shipping.moduleData.address-state-error"
aria-invalid="false" data-autom="address-field-state" value=""
data-recon-click="binding,actionClick,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseover="binding,actionMouseOver,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseout="binding,actionMouseOut,tradeUp.shipping.moduleData.address.state,binding"
data-recon-input="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-change="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusin="binding,setFocus,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusout="binding,clearFocus,tradeUp.shipping.moduleData.address.state,binding"
id="tradeUp.shipping.moduleData.address-state" required=""
class="form-dropdown form-dropdown-selectnone">
<option value="" selected="true">State</option>
<option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="AS">AS</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="MP">MP</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="US">US</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="VI">VI</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
编辑:
我现在设法进入了提到的对话框。如果您在控制台中执行以下命令,您应该能够将状态更改为 'MA'
ch=new MouseEvent('change', {view:window,bubbles:true});
s=document.getElementById('tradeUp.shipping.moduleData.address-state');
s.value='MA';
s.dispatchEvent(ch);
看起来 bootstrap 周围的 select 盒子需要一个变化事件,我们可以用上面的命令生成它。
经过进一步测试,我发现 {bubbles:true}
足以作为上面代码中的 "option" 参数(您可以省略 view:window
部分)。
如果您在使用不寻常的 id 处理 select
元素时遇到问题:您需要屏蔽其中的 .
字符,否则它们将被解释为表示 class 标识符。因此,selector for document.querySelector()
需要类似于 '#tradeUp\.shipping\.moduleData\.address-state'
.
在下面的几行中,您将找到一种更改 select 元素当前 selection 的方法。在这种情况下,我将其更改为 'MA'.
document.querySelector('#change').addEventListener('click',function(){
document.querySelector('#tradeUp\.shipping\.moduleData\.address-state').innerHTML=
['abc','def','ghi','jki','lmn'].map(function(s){return '<option>'+s+'</option>';}).join('');
})
// in case you wanted to change the value of the
// select programmatically, do the following:
document.querySelector('#tradeUp\.shipping\.moduleData\.address-state').value='MA';
<select aria-required="true" aria-describedby="tradeUp.shipping.moduleData.address-state-error"
aria-invalid="false" data-autom="address-field-state" value=""
data-recon-click="binding,actionClick,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseover="binding,actionMouseOver,tradeUp.shipping.moduleData.address.state,binding"
data-recon-mouseout="binding,actionMouseOut,tradeUp.shipping.moduleData.address.state,binding"
data-recon-input="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-change="binding,setValue,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusin="binding,setFocus,tradeUp.shipping.moduleData.address.state,binding"
data-recon-focusout="binding,clearFocus,tradeUp.shipping.moduleData.address.state,binding"
id="tradeUp.shipping.moduleData.address-state" required=""
class="form-dropdown form-dropdown-selectnone">
<option value="" selected="true">State</option><option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="AS">AS</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="MP">MP</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="US">US</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="VI">VI</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
<button id="change">change options</button>