微信小程序?qū)崿F(xiàn)通過js操作wxml的wxss屬性示例
本文實例講述了微信小程序?qū)崿F(xiàn)通過js操作wxml的wxss屬性。分享給大家供大家參考,具體如下:
微信小程序如何通過js操作html的css屬性:
在web端、手機(jī)端、webApp中可以通過js獲取dom的方式設(shè)置dom屬性。
微信小程序中,不能通過這種方式進(jìn)行操作。
如何在微信小程序中在wxml中操作wxss的屬性。
實現(xiàn)思路:
通過利用數(shù)據(jù)綁定實現(xiàn)動態(tài)改變樣式,
1、在wxxml標(biāo)簽內(nèi)嵌css屬性上綁定js的date值
2、通過js中綁定css屬性的date值改變wxml標(biāo)簽內(nèi)嵌的css屬性
實現(xiàn)效果:點擊所在地區(qū),彈出選擇地區(qū)的浮層

實現(xiàn)代碼:
editAddress.wxml:
<view class='top'>
<image bindtap='goBack' class='leftdection' src='../../../../images/leftdection02.png'></image>
<text>我的反饋</text>
<text class='righttag' bindtap='sendfeedback'>保存</text>
</view>
<view class='dialogWrap' style='display:{{isShowSelectAddress}}'>
<view class='selectaddress' >選擇地區(qū)</view>
</view>
<view class='item'>
<view style='color:#000;margin-top:10px;margin-left:10px'>收貨人 :</view>
<input class='inputclass' placeholder="收貨人" auto-focus/>
</view>
<view class='item'>
<view style='color:#000;margin-top:10px;margin-left:10px'>聯(lián)系方式 :</view>
<input class='inputclass' placeholder="聯(lián)系方式" />
</view>
<view class='item' bindtap='showselectregion'>
<view style='color:#000;margin-top:10px;margin-left:10px'>所在地區(qū) :</view>
<text style='margin-top:10px'>gdgdfgdf</text>
<image class='rightdirectionclass' src='../../../../images/leftdirection.png' ></image>
</view>
<view class='item'>
<view style='color:#000;margin-top:10px;margin-left:10px'>詳細(xì)地址 :</view>
<input class='inputclass' placeholder="詳細(xì)地址" />
</view>
<view class='item'>
<view style='color:#000;margin-top:10px;margin-left:10px'>標(biāo)簽 :</view>
<view class='addresstag' >家</view>
<view class='addresstag'>公司</view>
<view class='addresstag'>學(xué)校</view>
<view class='addresstag'>其他</view>
</view>
editAddress.wxss:
page{
width: 100%;height: 100%;position:relative
}
.leftdection{
width: 20px;height: 20px;position:absolute;left: 0;
margin-top: 5px;margin-left: 20px;
}
.righttag{
position:absolute;
right: 0;
margin-right: 10px;
color: red;
}
.item{
width: 100%;height: 50px;background: #fff;
display: flex;flex-direction: row;
border-bottom: 1px solid #000
}
.inputclass{
width: 220px;height: 25px;border: 0px solid #000;
margin-top: 10px
}
.addresstag{
width:25px;height:25px;border: 1px solid #000;padding-left:8px;
padding-top: 10px;font-size: 10px;margin-top: 10px;margin-left: 10px
}
.dialogWrap{
position: absolute;
width: 100%;height: 94%;background: rgba(0, 0, 0, 0.1);
}
.selectaddress{
position: absolute;bottom: 0;
width: 100%;background: rgba(0, 0, 0, 0.3);
height: 240px;
}
.rightdirectionclass{
width: 25px;height: 25px;position: absolute;right: 20px;
margin-top: 10px;
}
editAddress.js:
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
isShowSelectAddress:"none"
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: '編輯地址'
});
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面卸載
*/
onUnload: function () {
},
/**
* 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作
*/
onPullDownRefresh: function () {
},
/**
* 頁面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點擊右上角分享
*/
onShareAppMessage: function () {
},
goBack:function(){
wx.navigateBack({
});
},
showselectregion:function(){
this.setData({
isShowSelectAddress:"block"
})
}
})
希望本文所述對大家微信小程序開發(fā)有所幫助。
相關(guān)文章
JS實現(xiàn)textarea通過換行或者回車把多行數(shù)字分割成數(shù)組并且去掉數(shù)組中空的值
這篇文章主要介紹了JS實現(xiàn)textarea通過換行或者回車把多行數(shù)字分割成數(shù)組并且去掉數(shù)組中空的值的相關(guān)資料,需要的朋友可以參考下2018-10-10
Chart.js 輕量級HTML5圖表繪制工具庫(知識整理)
這篇文章主要介紹了Chart.js 輕量級HTML5圖表繪制工具庫,Chart.js基于HTML5 canvas技術(shù)支持所有現(xiàn)代瀏覽器,并且針對IE7/8提供了降級替代方案,感興趣的小伙伴們可以參考一下2018-05-05
微信小程序?qū)崿F(xiàn)省市區(qū)三級地址選擇
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)省市區(qū)三級地址選擇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-11-11
Javascript實現(xiàn)簡單的富文本編輯器附演示
這篇文章主要介紹了通過Javascript實現(xiàn)的簡單富文本編輯器,需要的朋友可以參考下2014-06-06
uniapp小程序使用高德地圖api實現(xiàn)路線規(guī)劃的示例代碼
路線規(guī)劃常用于出行路線的提前預(yù)覽,我們提供4種類型的路線規(guī)劃,分別為:駕車、步行、公交和騎行,滿足各種的出行場景,這篇文章主要介紹了uniapp小程序使用高德地圖api實現(xiàn)路線規(guī)劃,需要的朋友可以參考下2023-01-01
網(wǎng)絡(luò)之美 JavaScript中Get和Set訪問器的實現(xiàn)代碼
前兩天IE9 Beta版發(fā)布了,對于從事Web開發(fā)的朋友們來說真是個好消息啊,希望將來有一天各個瀏覽器都能遵循統(tǒng)一的標(biāo)準(zhǔn)。今天要和大家分享的是JavaScript中的Get和Set訪問器,和C#中的訪問器非常相似。2010-09-09
借助JavaScript腳本判斷瀏覽器Flash Player信息的方法
做了一個小的Demo,在測試時發(fā)現(xiàn)經(jīng)常報錯,對此總結(jié)了一下借助JavaScript腳本判斷瀏覽器Flash Player信息的方法,需要的朋友可以參考下2014-07-07

