使<select>可输入

用户需求可以在<select>可输入内容。在网上查找的方法,onchange事件方法,在我这里不能正常使用,我修改为onclick方法后OK
                <div style="position:relative;">
                    <span style="margin-left:100px;width:18px;overflow:hidden;">
                        <select id="selMarkDesc" style="width:118px;margin-left:-100px" οnclick="this.parentNode.nextSibling.value = this.value">
                            @foreach (var List in @ViewBag.ListMarkDesc)
                            {
                             <option value="@List.MarkDescription">@List.MarkDescription</option>
                            }
                        </select>
                    </span><input name="txtMarkDescSelect" id ="txtMarkDescSelect" style="width:100px;position:absolute;left:0px;">
                </div> 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你需要在 `<input>` 和 `<select>` 标签上添加 `v-model` 指令来实现双向绑定,以便在用户输入数据时,自动更新数据模型。同时,你需要添加一个数组用于存储用户数据,在点击“添加/修改”按钮时,将数据添加到数组中。还需要在表格中用 `v-for` 指令遍历数组,渲染每个用户的数据,并添加“删除”和“编辑”按钮的功能。具体代码如下: <template> <div id="app"> <div> <span>姓名:</span> <input type="text" v-model="name" /> </div> <div> <span>年龄:</span> <input type="number" v-model="age" /> </div> <div> <span>性别:</span> <select v-model="gender"> <option value="男">男</option> <option value="女">女</option> </select> </div> <div> <button @click="addOrUpdateUser">添加/修改</button> </div> <div> <table border="1" cellpadding="10" cellspacing="0"> <tr> <th>序号</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>操作</th> </tr> <tr v-for="(user, index) in userList" :key="index"> <td>{{ index + 1 }}</td> <td>{{ user.name }}</td> <td>{{ user.age }}</td> <td>{{ user.gender }}</td> <td> <button @click="deleteUser(index)">删除</button> <button @click="editUser(index)">编辑</button> </td> </tr> </table> </div> </div> </template> <script> export default { data() { return { name: '', age: '', gender: '男', userList: [] } }, methods: { addOrUpdateUser() { // 新建一个用户对象 const user = { name: this.name, age: this.age, gender: this.gender } // 判断是否是修改操作 if (this.editIndex !== undefined) { // 如果是修改操作,则替换原有用户数据 this.userList.splice(this.editIndex, 1, user) this.editIndex = undefined } else { // 如果是添加操作,则将用户数据添加到数组中 this.userList.push(user) } // 清空输入框中的数据 this.name = '' this.age = '' this.gender = '男' }, deleteUser(index) { // 删除指定位置的用户数据 this.userList.splice(index, 1) }, editUser(index) { // 将要修改的用户数据填入输入框 const user = this.userList[index] this.name = user.name this.age = user.age this.gender = user.gender // 记录当前的编辑位置 this.editIndex = index } } } </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值