如何在输入类型收音机中获取文本标签?
我做了这样的自定义收音机输入。 选择后,如何在无线电类型输入中获取文本标签的值并将其带入语法超链接“顺序链接”中?
let result = document.querySelector('#result');
document.body.addEventListener('change', function (e) {
let target = e.target;
let message;
switch (target.id) {
case '30day':
message = 'selected 30d package';
break;
case '6month':
message = 'selected 6m package';
break;
case '1year':
message = 'selected 1y package';
break;
}
result.textContent = message;
});
body {
background:#2d2d2d;
display:block;
justify-content: center;
align-items:center;
flex-wrap:wrap;
padding:0;
margin:20;
height:100vh;
width:100vw;
font-family: sans-serif;
color:#FFF;
}
.select {
display: flex;
flex-direction: column;
position: relative;
min-width: 50%;
height: 40px;
}
.option {
padding: 0 30px 0 10px;
min-height: 40px;
display: flex;
align-items: center;
background: #333;
border-top: #222 solid 1px;
position: absolute;
top: 0;
width: 100%;
pointer-events: none;
order: 2;
z-index: 1;
transition: background .4s ease-in-out;
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
}
.option:hover {
background: #666;
}
.select:focus .option {
position: relative;
pointer-events: all;
}
input {
opacity: 0;
position: absolute;
left: -99999px;
}
input:checked+label {
order: 1;
z-index: 2;
background: #666;
border-top: none;
position: relative;
}
input:checked+label:after {
content: '';
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid white;
position: absolute;
right: 10px;
top: calc(50% - 2.5px);
pointer-events: none;
z-index: 3;
}
input:checked+label:before {
position: absolute;
right: 0;
height: 40px;
width: 40px;
content: '';
background: #666;
}
<!-- custom radio selected -->
<div class="select" style="margin:20px;" tabindex="1">
<input class="selectopt" name="package" type="radio" id="" checked>
<label for="" class="option">Select package</label>
<input class="selectopt" name="package" type="radio" id="30day">
<label for="30day" class="option">30 d package</label>
<input class="selectopt" name="package" type="radio" id="6month">
<label for="6month" class="option">6 m package</label>
<input class="selectopt" name="package" type="radio" id="1year">
<label for="1year" class="option">1 y package</label>
</div>
<br/>
<!-- selected text result -->
<p id="result" style="color:#fff;"></p>
<!-- Order Link -->
<a href="https://api.whatsapp.com/send?phone=123456789&text=Hello%20I%20want%20to%20order%20(this is the package label value text)
" target="_blank">order link</a>
除此之外,如何为JavaScript中的多个电话号码创建一个变量,每次打开或刷新“订单链接”
超链接部分时,每次打开或刷新电话号码时,它是随机数“发送?电话= 123456789”
将随机更改。
我的意思是随机电话号码是预定义的,例如,每次打开网页或刷新时,都有5个选择的电话号码,例如:“ 123456789,1987654321,122223455,11222222334455,11222334455,112222334455 ,165456781“
则似乎更好。
<p id="result" style="color:#fff;"></p>
如果“订单链接”
单击但以前选择的自定义选择,
I made a custom radio input like this.
When selected, How do I get the value of the text label in the radio type input and bring it into the Syntax hyperlinks "Order Link"?
let result = document.querySelector('#result');
document.body.addEventListener('change', function (e) {
let target = e.target;
let message;
switch (target.id) {
case '30day':
message = 'selected 30d package';
break;
case '6month':
message = 'selected 6m package';
break;
case '1year':
message = 'selected 1y package';
break;
}
result.textContent = message;
});
body {
background:#2d2d2d;
display:block;
justify-content: center;
align-items:center;
flex-wrap:wrap;
padding:0;
margin:20;
height:100vh;
width:100vw;
font-family: sans-serif;
color:#FFF;
}
.select {
display: flex;
flex-direction: column;
position: relative;
min-width: 50%;
height: 40px;
}
.option {
padding: 0 30px 0 10px;
min-height: 40px;
display: flex;
align-items: center;
background: #333;
border-top: #222 solid 1px;
position: absolute;
top: 0;
width: 100%;
pointer-events: none;
order: 2;
z-index: 1;
transition: background .4s ease-in-out;
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
}
.option:hover {
background: #666;
}
.select:focus .option {
position: relative;
pointer-events: all;
}
input {
opacity: 0;
position: absolute;
left: -99999px;
}
input:checked+label {
order: 1;
z-index: 2;
background: #666;
border-top: none;
position: relative;
}
input:checked+label:after {
content: '';
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid white;
position: absolute;
right: 10px;
top: calc(50% - 2.5px);
pointer-events: none;
z-index: 3;
}
input:checked+label:before {
position: absolute;
right: 0;
height: 40px;
width: 40px;
content: '';
background: #666;
}
<!-- custom radio selected -->
<div class="select" style="margin:20px;" tabindex="1">
<input class="selectopt" name="package" type="radio" id="" checked>
<label for="" class="option">Select package</label>
<input class="selectopt" name="package" type="radio" id="30day">
<label for="30day" class="option">30 d package</label>
<input class="selectopt" name="package" type="radio" id="6month">
<label for="6month" class="option">6 m package</label>
<input class="selectopt" name="package" type="radio" id="1year">
<label for="1year" class="option">1 y package</label>
</div>
<br/>
<!-- selected text result -->
<p id="result" style="color:#fff;"></p>
<!-- Order Link -->
<a href="https://api.whatsapp.com/send?phone=123456789&text=Hello%20I%20want%20to%20order%20(this is the package label value text)
" target="_blank">order link</a>
In additional to, how do I create a variable for multiple phone numbers in javascript that works to be a random number every time a web page is opened or refreshed the phone number in the "Order Link"
hyperlinks section "send?phone=123456789"
will change randomly.
What I mean by random phone numbers are pre-defined ones, for example there are 5 choices of phone numbers to be randomized every time web page is opened or refreshed for eg random number is: "123456789,1987654321,122334455,112233445,165456781"
and it seems better with the warning text shown on
<p id="result" style="color:#fff;"></p>
if "order link"
clicked but custom selected not selected before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以通过获得等于无线电ID的属性来获取广播的标签。
另外,我添加了一个函数以生成具有特定长度的随机数以生成电话号码。
我使用
encodeuricomponent
来编码text
查询参数,因为其中有空格。Yes, You can get the label of the radio by getting its
for
attribute which equals the id of the radio.Also, I add a function to generate random numbers with specific length to generate the phone number.
I used
encodeURIComponent
to encode thetext
query parameter because there are spaces in it.