html5支持input[type=text]元素的占位符属性,但我需要处理不兼容的浏览器.我知道有一千个插件用于占位符,但我想创建1001个.
我能够获得input[placeholder]元素的句柄但是尝试获取占位符属性的值是返回undefined - $("input[placeholder]").attr("placeholder").
我正在使用jquery 1.6.2.
这是jsfiddle.我修改了代码以在兼容html5的浏览器中工作,仅用于测试目的.
HTML
<input type="text" name="email" size="10" placeholder="EMAIL ADDRESS">
Run Code Online (Sandbox Code Playgroud)
jQuery的
function SupportsInputPlaceholder() {
var i = document.createElement("input");
return "placeholder" in i;
}
$(document).ready(function(){
if(!SupportsInputPlaceholder()) {
//set initial value to placeholder attribute
$("input[placeholder]").val($("input[placeholder]").attr("placeholder"));
//create event handlers for focus and blur
$("input[placeholder]").focus(function() {
if($(this).val() == $(this).attr("placeholder")) {
$(this).val("");
}
}).blur(function() {
if($(this).val() == "") {
$(this).val($(this).attr("placeholder"));
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
感谢任何和所有的帮助,B
我有一个带有一个@RenderSection("scripts")部分的布局,我有一个捆绑包需要包含在本节中的某些视图中.我认为在视图中执行此操作会起作用,但它不会渲染脚本.
@section scripts {
@Scripts.Render("~/bundles/myBundle")
}
Run Code Online (Sandbox Code Playgroud)
在我看来,如何在脚本部分包含一个包?
布局
@Scripts.Render("~/bundles/jquery", "~/bundles/scripts")
@RenderSection("scripts", required: false)
Run Code Online (Sandbox Code Playgroud)
视图
@section scripts {
@Scripts.Render("~/bundles/movie")
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试observableArray用新内容替换项目中的所有内容.
var oldLocation = ko.utils.arrayFirst(self.locations(), function (item) {
return item.id == value.id;
});
self.locations.replace(self.locations.indexOf(oldLocation), new location(value));
self.locations.valueHasMutated();
Run Code Online (Sandbox Code Playgroud)
我也试过了
self.locations[self.locations.indexOf(location)] = new fizi.ko.models.location(value);
Run Code Online (Sandbox Code Playgroud)
但没有任何工作.正在检索索引,但项目的更新没有发生.
我正在尝试<i>为asp按钮包含一个Text属性,但它只是将html渲染为文本...
<asp:Button runat="server" ID="modify" ToolTip="Modify" CssClass="btn btn-mini" OnClick="modify_Onclick" Text='<i class="icon-edit"></i>' />
Run Code Online (Sandbox Code Playgroud)
我必须过度思考这个......
编辑:
我正在使用twitter bootstrap框架.这就是<i>标签的原因.这是一个例子:http://twitter.github.com/bootstrap/base-css.html#icons
我正在尝试拆分一个可以用逗号,空格或分号分隔的字符串.它还可以在每个分隔符后包含一个或多个空格.例如
22222,11111,23232
OR
22222, 11111, 23232
OR
22222; 11111; 23232
OR
22222 11111 23232
Run Code Online (Sandbox Code Playgroud)
其中任何一个都会生成一个包含三个值的数组 ["22222","11111","23232"]
到目前为止我有,var values = Regex.Split("22222, 11111, 23232", @"[\\s,;]+")但这产生了一个数组,其中包含第二个和第三个值,包括像这样的空格:
["22222"," 11111"," 23232"]
Run Code Online (Sandbox Code Playgroud) 我想删除最后一段Request.Url,例如......
http://www.example.com/admin/users.aspx/deleteUser
Run Code Online (Sandbox Code Playgroud)
会变成
http://www.example.com/admin/users.aspx
Run Code Online (Sandbox Code Playgroud)
我更喜欢linq但接受任何有效工作的解决方案.
我将json属性反序列化为枚举,但是当属性为空字符串时,我遇到了处理案例的问题.
将值""转换为"EnrollmentState"类型时出错
我正在尝试反序列化该state属性requiredItem.
{
"currentStage" : "Pre-Approved",
"stages" : ["Applicant", "Pre-Approved", "Approved", "Enrolled"],
"requiredItems" : [{
"id" : 1,
"name" : "Documents",
"state" : ""
}, {
"id" : 2,
"name" : "Eligibility Verification",
"state" : "complete"
}, {
"id" : 3,
"name" : "Placement Information",
"state" : "incomplete"
}
]
}
Run Code Online (Sandbox Code Playgroud)
RequiredItem 上课和枚举......
public class RequiredItem {
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>The identifier.</value>
public string id { get; …Run Code Online (Sandbox Code Playgroud) 我正在使用create-react-app实用程序创建一个ReactJS应用程序.如何配置它以使用包含服务工作者的文件?
编辑:从Javascript方面对我来说很清楚,在我的index.js中添加注册:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service_workers/sw.js')
.then(function(registration) {
// Registration was successful...
}).catch(function(err) {
// registration failed ...
});
}
Run Code Online (Sandbox Code Playgroud)
然后我的服务工作文件中的配置(对我来说是在service_wokers/sw.js):
self.addEventListener('install', function(event) {//my code here...});
self.addEventListener('activate', function(event) {//my code here...});
self.addEventListener('fetch', function(event) {//my code here...});
Run Code Online (Sandbox Code Playgroud)
当我运行此控制台时,控制台显示:ServiceWorker注册失败:DOMException:无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404).
该文件不存在,因为我没有配置Webpack来执行此操作.所以我试图用ouput复制sw.js文件:
test:
/\.(js)$/,
loader: "file?name=[path][name].[ext]&context=./service_workers",
include: '/service_worker'
Run Code Online (Sandbox Code Playgroud)
我认为没有必要说我对Webpack完全不熟悉.
我有一个抽象基类,我想实现一个方法来检索继承类的属性属性.像这样......
public abstract class MongoEntityBase : IMongoEntity {
public virtual object GetAttributeValue<T>(string propertyName) where T : Attribute {
var attribute = (T)typeof(this).GetCustomAttribute(typeof(T));
return attribute != null ? attribute.GetType().GetProperty(propertyName).GetValue(attribute, null) : null;
}
}
Run Code Online (Sandbox Code Playgroud)
并实施如此......
[MongoDatabaseName("robotdog")]
[MongoCollectionName("users")]
public class User : MonogoEntityBase {
public ObjectId Id { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public string email { get; set; }
[Required]
[DataType(DataType.Password)]
public string password { get; set; }
public IEnumerable<Movie> movies { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是当然使用上面的代码GetCustomAttribute()并不是一个可用的方法,因为这不是一个具体的类.
typeof(this)抽象类需要更改为什么才能访问继承类?或者这不是一个好的做法,我应该在继承类中完全实现该方法吗?
我将我的实体框架实体从我的Web项目和数据访问层拆分为一个单独的类库.在我的控制器中,我调用我的存储库来获取IEnumerable<RobotDog.Entities.Movie>,然后尝试序列化为json使用JavaScriptSerializer但是我得到一个循环引用,即使我正在使用该[ScriptIgnore]属性.
重要提示:最初我在一个项目下拥有我的实体,数据访问和网络,我能够在没有循环引用的情况下成功序列化我的实体.当我创建单独的图层时,我开始遇到问题.我没有改变任何实体.
RobotDog.Entities命名空间中我的一个实体的示例:
namespace RobotDog.Entities {
public class Character {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[MaxLength(200)]
public string Name { get; set; }
public virtual Person Person { get; set; }
[ScriptIgnore]
public virtual Movie Movie { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
namespace RobotDog.Web.Controllers {
public class MoviesController : Controller {
private UnitOfWork _unitOfWork = new UnitOfWork();
[HttpGet]
public ActionResult Index() {
var user = Membership.GetUser(User.Identity.Name);
if(user …Run Code Online (Sandbox Code Playgroud) asp.net-mvc entity-framework circular-reference javascriptserializer
c# ×4
asp.net-mvc ×2
asp.net ×1
attr ×1
attributes ×1
javascript ×1
jquery ×1
json.net ×1
knockout.js ×1
reactjs ×1
reflection ×1
regex ×1
split ×1
webpack ×1