option

Scala: convert string to Int or None

别来无恙 提交于 2019-11-26 19:57:05
问题 I am trying to get a number out of an xml field ... <Quantity>12</Quantity> ... via Some((recipe \ "Main" \ "Quantity").text.toInt) Sometimes there may not be a value in the xml, though. The text will be "" and this throws an java.lang.NumberFormatException. What is a clean way to get either an Int or a None? 回答1: scala> import scala.util.Try import scala.util.Try scala> def tryToInt( s: String ) = Try(s.toInt).toOption tryToInt: (s: String)Option[Int] scala> tryToInt("123") res0: Option[Int]

select操作option

二次信任 提交于 2019-11-26 19:38:15
jQuery获取Select选择的Text和Value: 代码如下: $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text var checkValue=$("#select_id").val(); //获取Select选择的Value var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值 var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值 jQuery添加/删除Select的Option项: $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项) $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置) $("#select

What values can appear in the “selected” attribute of the “option” tag?

廉价感情. 提交于 2019-11-26 17:43:05
I have some markup similar to the following: <select> <option selected="selected">Apple</option> <option selected="">Orange</option> </select> In this case, "Orange" shows as the selected item. I would have expected making the selected attribute blank would undo its effects. Is there a way to write this without simply leaving the attribute out? Different browser may treat this attribute differently. According to the MSDN documentation (for Internet Explorer): To select an item in HTML, it is not necessary to set the value of the SELECTED attribute to true. The mere presence of the SELECTED

JavaScript之Unspecified error或无法设置selected属性。未指明的错误。解决方案

别等时光非礼了梦想. 提交于 2019-11-26 17:22:57
  今天郁闷了大半天,从下午1点多开始到4点多,一直被一个JS的问题困扰,后来终于解决,写下作为笔记供自己以后查看吧。    问题背景: 自己写了一个多级联动的控件,其实加载数据均采用jQuery的ajax+json方式来调取和填充,方法如下: $.getJSON("/Ajax/xxx.ashx", { "action": "xx", "parentid": parentId, "r": Math.random() }, function (data) { $.each(data.codelist, function () { $("#sel_xx").append(sp.format("<option value=\"{0}\">{1}</option>", this.Id, this.Title)); }); if (_val != "") $("#sel_xx").val(_val); // 设置默认值--就是这在出的问题 $("#sel_xx").change(); });   以上方法在IE7、IE8、火狐、Google等浏览器中测试均正常,默认值可以正常加载。可以在IE6中测试时出现了如下错误:   IETester中:   纯IE6中:   想必上面的错误大家也碰到过,网上也有很多“解决”办法, 但是都不能最终性的解决问题 ,这里简单的列出作为对比吧(

JavaScript之Unspecified error或无法设置selected属性。未指明的错误。解决方案

百般思念 提交于 2019-11-26 17:21:55
  今天郁闷了大半天,从下午1点多开始到4点多,一直被一个JS的问题困扰,后来终于解决,写下作为笔记供自己以后查看吧。    问题背景: 自己写了一个多级联动的控件,其实加载数据均采用jQuery的ajax+json方式来调取和填充,方法如下: $.getJSON("/Ajax/xxx.ashx", { "action": "xx", "parentid": parentId, "r": Math.random() }, function (data) { $.each(data.codelist, function () { $("#sel_xx").append(sp.format("<option value=\"{0}\">{1}</option>", this.Id, this.Title)); }); if (_val != "") $("#sel_xx").val(_val); // 设置默认值--就是这在出的问题 $("#sel_xx").change(); });   以上方法在IE7、IE8、火狐、Google等浏览器中测试均正常,默认值可以正常加载。可以在IE6中测试时出现了如下错误:   IETester中:   纯IE6中:   想必上面的错误大家也碰到过,网上也有很多“解决”办法, 但是都不能最终性的解决问题 ,这里简单的列出作为对比吧(

How to check if an option is selected?

别来无恙 提交于 2019-11-26 17:07:39
$('#mySelectBox option').each(function() { if ($(this).isChecked()) alert('this option is selected'); else alert('this is not'); }); Apparently, the isChecked doesn't work. SO my question is what is the proper way to do this? Thanks. iambriansreed UPDATE A more direct jQuery method to the option selected would be: var selected_option = $('#mySelectBox option:selected'); Answering the question .is(':selected') is what you are looking for: $('#mySelectBox option').each(function() { if($(this).is(':selected')) ... The non jQuery (arguably best practice) way to do it would be: $('#mySelectBox

DOM

☆樱花仙子☆ 提交于 2019-11-26 17:02:15
DOM 简介 DOM 是 Document Object Model(文档对象模型)的缩写。 DOM 是 W3C(万维网联盟)的标准。 DOM 定义了访问 HTML 和 XML 文档的标准: “W3C 文档对象模型 (DOM) 是中立于平台和语言的接口,它允许程序和脚本动态地访问和更新文档的内容、结构和样式。” W3C DOM 标准被分为 3 个不同的部分: 核心 DOM - 针对任何结构化文档的标准模型 XML DOM - 针对 XML 文档的标准模型 HTML DOM - 针对 HTML 文档的标准模型 HTML DOM 定义了所有 HTML 元素的 对象 和 属性 ,以及访问它们的 方法 。换言之,HTML DOM 是关于如何获取、修改、添加或删除 HTML 元素的标准。 DOM 节点 根据 W3C 的 HTML DOM 标准,HTML 文档中的所有内容都是节点: 整个文档是一个文档节点 每个 HTML 元素是元素节点 HTML 元素内的文本是文本节点 每个 HTML 属性是属性节点 注释是注释节点 HTML DOM 节点树 HTML DOM 将 HTML 文档视作树结构。这种结构被称为节点树: HTML中的DOM操作 一些常用的 HTML DOM 方法: getElementById(id) - 获取带有指定 id 的节点(元素) appendChild(node) -

What's the difference of “./configure” option “--build”, “--host” and “--target”?

大城市里の小女人 提交于 2019-11-26 17:01:49
The script ./configure accepts 3 options --build , --host and --target . I'm confusing their roles. What's the difference and semantics of them? user124850 As noted in this blog post and alluded to in the GCC Configure Terms , --target only applies when you are compiling toolchains. When you are doing normal cross-compilation of a library or binary you use --build=the architecture of the build machine --host=the architecture that you want the file to run on However, when you are building toolchains, things can get more complicated. I think that the following is correct (though I can't say I've

React Warning: flattenChildren(…): Encountered two children with the same key

限于喜欢 提交于 2019-11-26 16:24:57
问题 Could someone please explain how to fix this error Warning: flattenChildren(...): Encountered two children with the same key I have replicated my code below, but for some reason CodePen is not showing the error. var FilterOptions = React.createClass({ changeOption: function(type, e) { var val = e.target.value; this.props.changeOption(val, type); }, render: function() { return ( <div className="filter-options"> <div className="filter-option"> <select id="product" name="Product" value={this

android: changing option menu items programmatically

帅比萌擦擦* 提交于 2019-11-26 15:25:37
问题 Is it possible to change the option menu items programmatically? Can anyone provide me with an example please? Also, I want to disable certain items, so that they don't listen to the clicks, is it possible? 回答1: For anyone needs to change the options of the menu dynamically: private Menu menu; // ... @Override public boolean onCreateOptionsMenu(Menu menu) { this.menu = menu; getMenuInflater().inflate(R.menu.options, menu); return true; } // ... private void hideOption(int id) { MenuItem item