我已经开发了一个AMP网站,其中有三个单选按钮。
当我单击清除所有按钮时,它将显示一个灯箱。在该灯箱上,我有两个按钮。
当用户单击灯箱中的“取消”时,将选中“显示所有单选输入”。我已经实现了amp状态变量更改。第一次单击取消时,它会在显示所有广播输入中正确检查,但是在此之后,如果我单击清除广播输入,然后再次单击取消按钮,它将不会再次显示所有广播输入。
在这里我在Codepen中添加了示例代码
示例代码链接:https://angular.io/guide/router
<!DOCTYPE html>
<html amp lang="en">
<head>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Favourites </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=1">
<link rel="manifest" href="/manifest.json">
<link rel="canonical" href="https://ampbyexample.com/introduction/hello_world/">
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<script async custom-element="amp-lightbox" src="https://cdn.ampproject.org/v0/amp-lightbox-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom="">
amp-lightbox {
background: rgba(0, 0, 0, .75);
}
amp-lightbox .align-content-center {
height: 100%;
}
.fav-lightbox{
background: #fff;
width: 70%;
position: relative;
top: 45%;
left: 0;
right: 0;
margin: 0 auto;
padding:15px;
border-radius: 10px;
padding-bottom: 35px;
}
.fav-lightbox h4{
color: #000;
margin:0;
font-weight: 600;
margin-bottom: 10px;
}
.fav-pop-title{
overflow: auto;
}
.lightbox-btn-grup{
float: right;
}
.lightbox-btn-grup input[type="submit"], .cancel-btn {
background: none;
border: none;
color:#3A98FF;
font-size: 16px;
}
.lightbox-btn-grup .favOkBtn{
font-weight: 700;
}
.cancel-btn{
text-decoration: none;
}
</style>
</head>
<body>
<amp-state id="partnerLogo">
<script type="application/json">
{
"chkRadio" : "show_all"
}
</script>
</amp-state>
<div class="favorite-page-wrapper static-page-margin">
<div class="favorite-content-filter">
<label>
<input name="filter" value="show_all" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})" checked
[checked]="partnerLogo.chkRadio == 'show_all' ? checked : '' ">
show all
</label>
<label>
<input name="filter" value="show_favorite" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"
[checked]="partnerLogo.chkRadio == 'show_fav' ? checked : '' ">
show only favorites
</label>
<label>
<amp-lightbox id="favorite-lightbox" layout="nodisplay">
<div class="fav-lightbox" role="button" tabindex="0">
<div class="fav-pop-title">
<h4>Are you sure you want to clear entire list?</h4>
</div>
<div class="lightbox-btn-grup">
<input type="submit" value="Cancel" role="button" tabindex="0"
on="tap:favorite-lightbox.close ,AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"/>
<input type="submit" value="OK" role="button" tabindex="0" class="favOkBtn"
on="tap:favorite-lightbox.close">
</div>
</div>
</amp-lightbox>
<input
name="filter" type="radio" role="button"
tabindex="0" on="change:favorite-lightbox"
[checked]="partnerLogo.chkRadio != show_all ? checked : '' "> Clear All
</label>
</div>
</div>
</body>
</html>
有什么建议吗?
答案 0 :(得分:1)
好吧,最后,我从amp-team找到了解决此问题的方法。我正在发布该答案,以便如果有人遇到相同的问题,他们可以轻松解决它
<div class="favorite-content-filter">
<label>
<input name="filter" value="show_all" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})" checked
[checked]="partnerLogo.chkRadio == 'show_all' ? checked : '' ">
show all
</label>
<label>
<input name="filter" value="show_favorite" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"
[checked]="partnerLogo.chkRadio == 'show_fav' ? checked : '' ">
show only favorites
</label>
<label>
<amp-lightbox id="favorite-lightbox" layout="nodisplay">
<div class="fav-lightbox" role="button" tabindex="0">
<div class="fav-pop-title">
<h4>Are you sure you want to clear entire list?</h4>
</div>
<div class="lightbox-btn-grup">
<input type="submit" value="Cancel" role="button" tabindex="0"
on="tap:favorite-lightbox.close ,AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"/>
<input type="submit" value="OK" role="button" tabindex="0" class="favOkBtn"
on="tap:favorite-lightbox.close">
</div>
</div>
</amp-lightbox>
<input
name="filter" type="radio" role="button"
tabindex="0" on="change:favorite-lightbox, AMP.setState({partnerLogo:{chkRadio : ''}})"
[checked]="partnerLogo.chkRadio != show_all ? checked : '' "> Clear All
</label>
</div>
灯箱打开时,我只需要将partnerLogo.chkRadio设置为其他内容。否则,状态将与选定的无线电不同步。