使用jquery获取单个记录(get single records using jquery)
在PHP的Foreach循环中,我只点击'product_title'和'email'。 代码如下。
foreach($abs_records as $abs) { <tr> <td><input type="checkbox" name="case[]" class="case" ></td> <td><?php echo $abs['product_id']; ?></td> <td><?php echo $abs['product_title']; ?></td> <td><?php echo $abs['user_email']; ?></td> <td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td> </tr><?php } ?>
使用Jquery点击'发送'我将获得'Product_title'和'user_email'的单一时间值的结果
你能建议我吗?
谢谢。
In Foreach loop of php i get on click event only 'product_title' and 'email'. code is as bellow.
foreach($abs_records as $abs) { <tr> <td><input type="checkbox" name="case[]" class="case" ></td> <td><?php echo $abs['product_id']; ?></td> <td><?php echo $abs['product_title']; ?></td> <td><?php echo $abs['user_email']; ?></td> <td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td> </tr><?php } ?>
Using Jquery click on 'Send' i will get the result of Single Time value of 'Product_title' and 'user_email'
Can you suggest me.
Thanks.
原文:https://stackoverflow.com/questions/36952121
最满意答案
我已经增强了这个答案 ,为您提供了一个更全面的解决方案,具有更好的语义语法。
using System; using System.ComponentModel; public static class EnumExtensions { // This extension method is broken out so you can use a similar pattern with // other MetaData elements in the future. This is your base method for each. public static T GetAttribute<T>(this Enum value) where T : Attribute { var type = value.GetType(); var memberInfo = type.GetMember(value.ToString()); var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false); return (T)attributes[0]; } // This method creates a specific call to the above method, requesting the // Description MetaData attribute. public static string ToName(this Enum value) { var attribute = value.GetAttribute<DescriptionAttribute>(); return attribute == null ? value.ToString() : attribute.Description; } }
此解决方案在Enum上创建了一对扩展方法,以便您可以执行所需的操作。 我稍微增强了您的
Enum
代码,以使用System.ComponentModel.DataAnnotations
的DisplayAttribute
类的语法。using System.ComponentModel.DataAnnotations; public enum Days { [Display(Name = "Sunday")] Sun, [Display(Name = "Monday")] Mon, [Display(Name = "Tuesday")] Tue, [Display(Name = "Wednesday")] Wed, [Display(Name = "Thursday")] Thu, [Display(Name = "Friday")] Fri, [Display(Name = "Saturday")] Sat }
要使用上述扩展方法,您现在只需调用以下内容:
Console.WriteLine(Days.Mon.ToName());
要么
var day = Days.Mon; Console.WriteLine(day.ToName());
I've enhanced this answer to give you a more fully rounded-out solution, with better semantic syntax.
using System; using System.ComponentModel; public static class EnumExtensions { // This extension method is broken out so you can use a similar pattern with // other MetaData elements in the future. This is your base method for each. public static T GetAttribute<T>(this Enum value) where T : Attribute { var type = value.GetType(); var memberInfo = type.GetMember(value.ToString()); var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false); return (T)attributes[0]; } // This method creates a specific call to the above method, requesting the // Description MetaData attribute. public static string ToName(this Enum value) { var attribute = value.GetAttribute<DescriptionAttribute>(); return attribute == null ? value.ToString() : attribute.Description; } }
This solution creates a pair of extension methods on Enum, to allow you to do what you're looking for. I've enhanced your
Enum
code slightly, to use the syntax for theDisplayAttribute
class ofSystem.ComponentModel.DataAnnotations
.using System.ComponentModel.DataAnnotations; public enum Days { [Display(Name = "Sunday")] Sun, [Display(Name = "Monday")] Mon, [Display(Name = "Tuesday")] Tue, [Display(Name = "Wednesday")] Wed, [Display(Name = "Thursday")] Thu, [Display(Name = "Friday")] Fri, [Display(Name = "Saturday")] Sat }
To use the above extension method, you would now simply call the following:
Console.WriteLine(Days.Mon.ToName());
or
var day = Days.Mon; Console.WriteLine(day.ToName());
相关问答
更多-
Swift枚举:从int值获取字符串枚举的枚举值(Swift enums: Getting enum value for string enum from int value)[2023-01-22]
根据您的设置,您可以: let n = 2 let stringValue = Industry.allValues[n - 1].rawValue Based on your setup you could do: let n = 2 let stringValue = Industry.allValues[n - 1].rawValue -
你可以使用values()方法: 例如Status.values()[0]将在您的情况下返回PAUSE,如果打印,将会调用toString()并打印“PAUSE”。 if status is of type Status enum, status.name() will give you its defined name.
-
枚举值到字符串(Enum value to string)[2023-05-08]
是的,您可以使用.ToString()获取枚举的字符串值,但是您不能在switch语句中使用.ToString() 。 Switch语句需要常量表达式,而.ToString()不会在运行时进行求值,因此编译器会抛出错误。 为了获得所需的行为,通过稍微改变方法,您可以使用enum.Parse()将action字符串转换为枚举值,并改为使用该枚举值。 从.NET 4开始,您可以使用Enum.TryParse() ,并在前期执行错误检查和处理,而不是在交换机主体中。 如果是我,我会将字符串解析为枚举值,并打开它, ... -
你不行 我想你有四个选择。 所有四个都提供了一个解决方案,但是有一个稍微不同 选项一: 在枚举上使用内置的name() String name = Modes.mode1.name(); // Returns the name of this enum constant, exactly as declared in its enum declaration. 选项二: 如果你想要更多的控制,添加覆盖属性到你的枚举 public enum Modes { mode1 ("Fancy Mod ...
-
正如@Reniuz已经通过使用Enum.Parse或更好的Enum.TryParse所建议的Enum.TryParse : public virtual AccountType? AccountType { get { AccountType type; if (Enum.TryParse(AccountTypeString, out type)) return type return null; } s ...
-
我已经增强了这个答案 ,为您提供了一个更全面的解决方案,具有更好的语义语法。 using System; using System.ComponentModel; public static class EnumExtensions { // This extension method is broken out so you can use a similar pattern with // other MetaData elements in the future. This is ...
-
将值枚举到字符串PHP中(Enum values into string PHP)[2021-09-13]
您可以为值声明一个数组。 $bookingTypes = array( 'Single', 'Group', 'Tournament' ); 并使用您的$booking['bookingType']获取字符串: echo $bookingTypes[$booking['bookingType']]; // Tournament 如果您有自定义值而不是0, 1 and 2 : $bookingTypes = array( 9 => 'Single', 20 => ' ... -
TypeScript并不便于将枚举值类型扩展为它们派生的字符串或数字文字。 你可以使用条件类型相当接近你想要的东西: type Extractable
= T extends U ? any : never type NotString = string extends T ? never : any function promoteStringToFMEvents & Extractable > ... -
您应该在枚举中添加字段,然后实现自己的valueOf()方法。 请查看提供更多详细信息的文章: http : //java.dzone.com/articles/enum-tricks-customized-valueof You should add field(s) to your enum and then implement kind of your own valueOf() method. Please take a look on article that gives more details ...
-
JLS(Java语言规范)告诉我们两个重要事实: Java枚举字段必须是有效的标识符。 EnumConstants: EnumConstant EnumConstants , EnumConstant EnumConstant: Annotations_opt Identifier Arguments_opt ClassBody_opt Arguments: ( ArgumentList_opt ) EnumBodyDeclarations: ; ClassBo ...