javascript - Javascript中的switch语句附加它需要一个分号并且不执行
问题描述
我试图在对特定 Div 的 Ajax 调用上附加一些 HTML 元素。但是,我得到了日期,并尝试使用回调函数在追加中进行切换,以便我可以使用该开关。如果没有开关,我的代码可以很好地执行,但是当我在附加中插入开关时,它会显示预期的分号或预期的(JS)表达式
append方法里面的switch有什么问题?
这是我的代码
function showCategoryJobs() {
var categoryId = $('#search-by-dropdown').val();
$.ajax({
url: '@Url.Action("SearchByCategory", "AllJobs")',
type: 'GET',
dataType: 'json',
data: { category: categoryId },
success: function (posts) {
$(".job-container").html("");
//$(".job-container").load(" .job-container");
$.each(posts.FindJobs, function (x, post) {
var newdate = new Date(post.PostedDate + 'Z');
$(".job-container").append(function () {
`
<li class="separate-job" id="All-Jobs-Id" value="` + post.jobId + `">
<div class="content-li-All-Jobs">
<h2 class="content-li-All-headline" id="headline-for-Update">`+ post.Headline + `</h2>
<a class="btn btn-success bid-for-job" value="`+ post.jobId + `" href="#">Bid now</a>
<div class="user">
<blockquote class="blockquote">
<p class="mb-0">
<div class="about-job">`+ post.About + `</div>
</p>
<div class="blockquote-footer">
<cite>-`+ post.Username + `</cite>
</div>
</blockquote>
</div>
<div class="pictures-li">
`+ $.map(post.JobPictures, function (i, pictures) {
if (i != null) {
return `<div class="separate-pic">
<img class="posted-pic" src="data:image/jpg;base64,${i.JobImageContentBytes}" alt="" />
</div>`;
}
}).join("") + `
</div>
<div class="job-date-li">
Posted `+ switch (newdate.getDate()) {
case 1:
case 21:
case 31:
newdate.getDate(); + '<text>th</text>'
break;
case 2:
case 22:
newdate.getDate(); + '<text>th</text>'
break;
case 3:
case 23:
newdate.getDate(); + '<text>th</text>'
break;
default:
newdate.getDate(); +'<text>th</text>'
break; }; + ` ` + newdate.getMonth() + ` ` + newdate.getFullYear() +
`
</div>
<div class="-job-town">Area | <span class="city">`+ post.JobCity + `</span></div>
</div>
</li>
`
});
});
}
});
}
解决方案
getDate() 后删除分号
推荐阅读
- java - Java中的多个套接字
- razor - SelectList(Model.RoleDropDownDisp,"RoleId","RoleName") 导致 ArgumentNullException:值不能为空。(参数“项目”)
- apache - .htaccess 文件子文件夹重定向
- php - 最新访问的模块无法正常工作
- c# - 如何从另一个窗口编辑文本框
- c - FreeRTOS 两个 CPU 时钟
- python - 具有 Kroonenberg 和 De Leeuw 初始化的 CP-ALS 算法
- javascript - 如何根据嵌套对象数组的对象搜索输入查找所有匹配值
- javascript - 我将 jQuery 转换为 JavaScript,但我有问题
- tortoise-orm - 预取在 Tortoise-ORM 中没有按预期工作