如何解决Javascript根据名称输入创建Slug,并将其显示在禁用的Slug输入上
因此,我一直在尝试使用Javascript创建一个插件,并允许我的用户在甚至按Submit之前就可以看到该插件。这是我的Javascript代码:
function slugify(text) {
return text
.toString() // Cast to string
.toLowerCase() // Convert the string to lowercase letters
.normalize('NFD') // The normalize() method returns the Unicode Normalization Form of a given string.
.trim() // Remove whitespace from both sides of a string
.replace(/\s+/g,'-') // Replace spaces with -
.replace(/[^\w\-]+/g,'') // Remove all non-word chars
.replace(/\-\-+/g,'-'); // Replace multiple - with single -
}
function listingslug(text) {
document.getElementById("slug").value = slugify(text);
}
这是我正在使用的HTML,它正在使用Bootstrap 4:
<form class="form">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" onkeyup="listingslug(this)" id="name" name="name" placeholder="Example input placeholder">
</div>
<label for="slug">Your vanity URL</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon3">{{ env('APP_URL') }}/listing/</span>
</div>
<input type="text" class="form-control" id="slug" name="slug" aria-describedby="basic-addon3">
</div>
</form>
我收到一个错误消息,表明listingslug不存在。我正在使用Laravel mix来编译我的代码。我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。