当我将内联样式应用于 html 元素时,我在我的 ASP.NET MVC 项目中有一个奇怪的行为 - 它们没有显示在浏览器中。但是,如果我使用 css 类将相同的样式放在外部 css 文件中,它将起作用(即使将 css 类<style>放在同一页面上的标记中也不起作用。
例子:
不工作
<div style="height: 100px; width: 100px; background: red;">
ABC
</div>
Run Code Online (Sandbox Code Playgroud)
不工作
<!DOCTYPE html>
<html>
<head>
<style>
.myClass {
height: 100px;
width: 100px;
background: red;
}
</style>
</head>
<body>
<div class="myClass">
ABC
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在职的
mystyle.css
.myClass {
height: 100px;
width: 100px;
background: red;
}
Run Code Online (Sandbox Code Playgroud)
索引.cshtml
<div class="myClass">
ABC
</div>
Run Code Online (Sandbox Code Playgroud)
如果我不使用cshtml文件而只加载静态html文件,则所有变体都有效。
这是为什么?我们如何修复它?
我有一个使用JQuery ui自动完成功能的脚本,可以很好地工作。有一个搜索过程显示用户firsname和lastname。但是在我的数据库中,还有用户的图片,我想在建议中显示其名字和姓氏。
(在数据库中,pic包含图像URL)
剧本:
$(function() {
$("#search").autocomplete({
source: "autocomplete.php",
minLength: 1,
select: function(event, ui) {
var url = ui.item.id;
if(url != '') {
location.href = '...' + url;
}
},
html: true,
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
});Run Code Online (Sandbox Code Playgroud)
autocomplete.php
<?php
if ( !isset($_REQUEST['term']) ) {
exit;
}
$mysqli = new MySQLi($DB_host,$DB_login,$DB_pass,$DB_select);
$term = trim(strip_tags($_GET['term']));
$term = preg_replace('/\s+/', ' ', $term);
$a_json = array();
$a_json_row = array();
$a_json_invalid = array(array("id" => "#", "value" => $term, "label" => "Only …Run Code Online (Sandbox Code Playgroud)使用MVC5和剃须刀。
情况1:
var url='~/path';
<a href='@url'>test</a>
Run Code Online (Sandbox Code Playgroud)
错误我得到:http : //www.example.com/~/path
情况#2
var url='/path';
<a href='~/@url'>test</a>
Run Code Online (Sandbox Code Playgroud)
正确,我知道:http : //www.example.com/path
有没有办法让剃须刀正确解释波浪号?换句话说,如果我绝对想像第一种情况那样在字符串中包含代字号,是否有办法使其工作?