我想colors通过选项创建具有类名的div .on("change").它运作良好,但只要我改变选项,就会div创建越来越多的选项.但我只有两个colors,所以任何时候我改变选项,我只想看到两个div:"蓝色"和"红色".我试图$('.result').remove();在追加之前使用.但是没有附加任何内容.
$(document).ready(function() {
$("#select").on("change", function() {
$(".colors").each(function() {
var color = $(this).attr('title');
$(".result").append("<div>" + color + "</div>");
});
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select">
<option class="colors" title="blue">a</option>
<option class="colors" title="red">b</option>
<option title="green">c</option>
</select>
<div class="result"></div>Run Code Online (Sandbox Code Playgroud)
我想在ubuntu 16.04上升级我的apache php版本.现在phpinfo()显示7.0.26.我该如何升级?
我想升级到phpversion 7.2.sudo apt install php7.2,不更新apache php版本.如何更新apache php版本.
我在SO上读了几个答案,其中一个建议我做以下但我得到array的结果.
基本上我们在搜索结果上,我们有这个:
$term = $_GET['s'];
Run Code Online (Sandbox Code Playgroud)
如果我这样做echo $term;,我得到America 2018,而我想有:
Location: America
Time: 2018
Run Code Online (Sandbox Code Playgroud)
我尝试使用爆炸:
$term = explode("\n", $term); echo $term;
Run Code Online (Sandbox Code Playgroud)
但结果是 Array
我需要一些以下格式的变量:
$m_01;
$m_02;
$m_03;
.....
.....
.....
$m_12;
Run Code Online (Sandbox Code Playgroud)
变量中的数字是日历的月份。我可以分别声明12个变量。但是,我想使用循环来声明变量。所以我做了这样的事情。
for($i = 1; $i <= 12; $i++) {
if($i<10)
$month = '0'.$i;
else
$month = $i;
$m_$i;
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到一些错误:-
解析错误:语法错误,第 412 行 /var/www/html/custom/ci/Dotell_customer/application/controllers/login.php 中出现意外的“$month”(T_VARIABLE)
我怎样才能克服这个问题?
笔记:
$$month creates a variable 01;
Run Code Online (Sandbox Code Playgroud)
有什么办法可以让变量消失m_01吗?
PS我知道数组。我只是想学习PHP变量变量。
我正在尝试创建一个程序,用户可以在其中输入2个数字,程序将获取2个数字并将它们相乘以得到答案.但是,对于这个具体的例子,我只是试图从用户那里获取2个数字,我希望Java添加它们.例如1+1=2,而不是1+1=11.
我的代码:
import javax.swing.JOptionPane;
public class MultiplicationTables {
public static void main(String args[]) {
//declare variables
String num1;
String num2;
int ans=0;
num1=JOptionPane.showInputDialog(null,"Enter a number");
num2=JOptionPane.showInputDialog(null,"Enter another number");
ans=Integer.parseInt(num1);
ans=Integer.parseInt(num2);
JOptionPane.showMessageDialog(null,"Your answer is " + (num1+num2));
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个方法:
private boolean method(String... arguments){
for (String argument : arguments) {
...
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我想知道有多少参数传递给我的方法.
是否有一种干净的方法,而不是仅仅创建一个迭代每个参数并逐个计算它们的方法?
如果传递给我的方法的参数数量是奇数,我的目标是返回false.
我有两个数组:
$arr1 = array(
'attributes' => array(
'fruit' => 'banana',
),
);
$arr2 = array(
'attributes' => array(
'color' => 'red',
),
);
$result = array_merge($arr1, $arr2);
Run Code Online (Sandbox Code Playgroud)
结果是:
Array ( [attributes] => Array ( [color] => red ) )
Run Code Online (Sandbox Code Playgroud)
但我的预期结果:
Array ( [attributes] => Array ( [color] => red [fruit] => banana ) )
Run Code Online (Sandbox Code Playgroud)
我做错了什么?我应该使用array_merge, 或者只是使用array_push并且只使用('color'=>'red')会更好更容易吗?
我正在尝试使用增强的for循环来添加数组中的元素.如果我使用正常的for循环,它可以工作.但是,当我使用增强的for循环时,它会引发IndexOutOfBounds异常,我不确定为什么会发生这种情况?
int[ ] array = {1,2,3};
int total = 0;
for(int counter : array) {
total = total + array[counter];
}
System.out.println(total);
Run Code Online (Sandbox Code Playgroud) 使用 Java 11 我想知道如何使用 Stream API 将所有组匹配提取到单行中的字符串列表中。
鉴于此正则表达式和字符串:
String regexp = "(\\d\\d\\d)-(\\d)-(\\d\\d)";
String str = "123-8-90";
Run Code Online (Sandbox Code Playgroud)
我知道如何在多行中获得结果:
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher(str);
List<String> matches = new ArrayList<>();
if (matcher.find()) {
matches.add(matcher.group(1));
matches.add(matcher.group(2));
matches.add(matcher.group(3));
}
System.out.println(matches);
Run Code Online (Sandbox Code Playgroud)
这将打印 3 个不同数字字符串的预期列表: [123, 8, 90]
我试图在一个班轮中实现相同的目标:
List<String> matches = Pattern.compile(regexp)
.matcher(str)
.results()
.map(MatchResult::group)
.collect(Collectors.toList());
System.out.println(matches);
Run Code Online (Sandbox Code Playgroud)
这会打印出意外:[123-8-90]
如何在流中使用 MatchResult::group(int) 方法?
我正在学习JS.所以我正在尝试创建一个函数,但"其他"部分不起作用.你能帮我理解为什么吗?
function accesSite() {
let ageLimite = prompt("How old are you ?");
if (ageLimite >= 16) {
var yes = " Ok, you can drive ! ";
} else {
var no = "No, you can't drive!";
}
let message = "Can you drive ?" + yes || no;
return message
}
alert(accesSite());Run Code Online (Sandbox Code Playgroud)
java ×4
php ×4
regex ×2
algorithm ×1
arguments ×1
array-merge ×1
array-push ×1
arrays ×1
ide ×1
iteration ×1
java-8 ×1
java-stream ×1
javascript ×1
jquery ×1
math ×1
variables ×1